Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gisce/primestg
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.49.1
Choose a base ref
...
head repository: gisce/primestg
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[bumpversion]
current_version = 1.49.1
current_version = 1.55.1
4 changes: 2 additions & 2 deletions .github/workflows/python2.7-app.yml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
@@ -35,4 +35,4 @@ jobs:
pip install -e .
- name: Test with mamba
run: |
mamba --enable-coverage
mamba --enable-coverage
24 changes: 21 additions & 3 deletions primestg/cli.py
Original file line number Diff line number Diff line change
@@ -6,13 +6,14 @@
from pytz import timezone
from primestg.ziv_service import ZivService
import base64
from primestg.cycle.cycles import CycleFile

TZ = timezone('Europe/Madrid')

from primestg.service import Service, format_timestamp
from primestg.contract_templates import CONTRACT_TEMPLATES
from primestg.utils import DLMSTemplates

import json

REPORTS = [
'get_instant_data',
@@ -31,7 +32,9 @@
'powers': {'order': 'B02', 'func': 'get_powers'},
'dlms': {'order': 'B12', 'func': 'order_raw_dlms'},
# CNC config
'cnc_ftpip': {'order': 'B07', 'func': 'set_concentrator_ipftp'}
'cnc_ftpip': {'order': 'B07', 'func': 'set_concentrator_ip'},
'cnc_ntpip': {'order': 'B07', 'func': 'set_concentrator_ip'},
'cnc_stgip': {'order': 'B07', 'func': 'set_concentrator_ip'},
}


@@ -113,7 +116,7 @@ def get_sync_sxx(**kwargs):
)
@click.option("--ip", "-i", default="10.26.0.4", help='IP i.e CNC FTPIp')
def sends_order(**kwargs):
"""Sends on of available Orders to Meter or CNC"""
"""Sends one of available Orders to Meter or CNC"""
id_pet = get_id_pet()
s = Service(id_pet, kwargs['cnc_url'], sync=True)
order_name = kwargs['order']
@@ -172,6 +175,14 @@ def sends_order(**kwargs):
vals = {
'IPftp': kwargs['ip']
}
elif order_name == 'cnc_ntpip':
vals = {
'IPNTP': kwargs['ip']
}
elif order_name == 'cnc_stgip':
vals = {
'IPstg': kwargs['ip']
}

vals.update({
'date_to': format_timestamp(datetime.now()+timedelta(hours=1)),
@@ -245,5 +256,12 @@ def send_ziv_cycle(**kwargs):
result = zs.send_cycle(filename=kwargs['filename'], cycle_filedata=content)
print(result.content)

@primestg.command(name='parse_cycle')
@click.argument('filename', required=True)
def parse_cycle(**kwargs):
"""Prints dict with cycle data from CNC csv"""
c = CycleFile(path=kwargs['filename'])
print(json.dumps(c.data, indent=4, default=str))

if __name__ == 'main':
primestg()
2 changes: 2 additions & 0 deletions primestg/cycle/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# coding=utf-8
from primestg.cycle.cycles import CycleFile
52 changes: 52 additions & 0 deletions primestg/cycle/cycles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# coding=utf-8
import csv
from os.path import isfile
from os import access, R_OK
import io
import datetime
import re


class CycleFile(object):

def __init__(self, path='', content=None):
self.data = []
if path and isfile(path) and access(path, R_OK):
with io.open(path, encoding='utf-8') as fp:
self.parse(fp)
elif content is not None:
with io.StringIO(content) as fp:
self.parse(fp)

def parse(self, fp):
csvreader = csv.reader(fp, delimiter=';')
for row in csvreader:
# skip info header and tail
if len(row) < 6:
# TODO parse file date
continue
if row[0] == 'time':
# header
continue

exec_date_str, reg_name, operation, obis, class_id, element_id, result_str = row[:7]
action_return = None
if len(row) > 7:
action_return = row[-1]

exec_date = datetime.datetime.strptime(exec_date_str, '%Y/%m/%d %H:%M:%S')
clean_data = re.sub(
'array|structure', '', re.sub('[{}]', '', re.sub('[a-z_]*\{([0-9/: ]+)\}', ';\\1', result_str))
)
data = clean_data.split(';')[1:]
result = {
'timestamp': exec_date,
'reg_name': reg_name,
'operation': operation,
'obis': obis,
'class_id': class_id and int(class_id) or None,
'element_id': element_id and int(element_id) or None,
'data': data
}

self.data.append(result)
9 changes: 9 additions & 0 deletions primestg/dlms_templates.py
Original file line number Diff line number Diff line change
@@ -72,5 +72,14 @@
{'obis': "1.0.0.4.5.255", 'class': "1", 'element': "2"}, # primary voltage
{'obis': "1.0.0.4.6.255", 'class': "1", 'element': "2"}, # secondary voltage
],
},
'GET_INSTANT': {
'description': 'Gets instant data',
'origin': 'library',
'category': 'info',
'params': [],
'data': [
{'obis': "0.0.21.0.5.255", 'class': "7", 'element': "2"}, # instant data
],
}
}
Loading