changed last seen datetime formater of datasource from timestamp to strftime

Merge branch 'develop'
pull/85/head
13621160019@163.com 2021-09-22 14:50:57 +08:00
commit 10404da946
3 changed files with 26 additions and 9 deletions

View File

@ -28,7 +28,7 @@
<td class="text-center">{{ datasource.gateway.name }}</td>
<td class="text-center">{{ datasource.protocol }}</td>
<td class="text-center">{{ datasource.connection }}</td>
<td class="text-center">{{ datasource.last_seen_datetime | date:'yyyy-MM-dd HH:mm:ss'}}</td>
<td class="text-center">{{ datasource.last_seen_datetime }}</td>
<td class="text-center">
<a ng-click="editDataSource(datasource)"
class="btn btn-primary btn-rounded btn-xs">{{'SETTING.EDIT' | translate}}</a>

View File

@ -312,7 +312,7 @@ Result in JSON
| uuid | string | Data Source UUID |
| protocol | string | Protocol Type Supported: 'modbus-tcp', 'modbus-rtu', 'bacnet-ip', 's7', 'profibus', 'profinet', 'opc-ua', 'lora', 'simulation', 'controllogix', 'weather', 'mysql', 'sqlserver', 'postgresql', 'oracle', 'mongodb', 'influxdb' |
| connection | json | Connection data in JSON. BACnet/IP example: {"host":"10.1.2.88"}, Modbus TCP example: {"host":"10.1.2.88", "port":502}, S7 example: {"host":"10.1.2.202", "port":102, "rack": 0, "slot": 2}, ControlLogix example: {"host":"10.1.2.88","port":44818,"processorslot":3} OPC UA example: {"url":"opc.tcp://10.1.2.5:49320/OPCUA/SimulationServer/"} |
| last_seen_datetime| float | Indicates the last time when the data source was seen in a number of milliseconds since January 1, 1970, 00:00:00, universal time |
| last_seen_datetime| string | Indicates the last time when the data source was seen in local timezone |
| status | string | 'online' or 'offline' determined by last seen datetime|
* GET all Data Sources

View File

@ -3,7 +3,7 @@ import simplejson as json
import mysql.connector
import config
import uuid
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta
from core.userlogger import user_logger
@ -41,18 +41,26 @@ class DataSourceCollection:
cursor.close()
cnx.disconnect()
timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6])
if config.utc_offset[0] == '-':
timezone_offset = -timezone_offset
result = list()
if rows is not None and len(rows) > 0:
for row in rows:
if isinstance(row['last_seen_datetime_utc'], datetime):
last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \
timedelta(minutes=timezone_offset)
last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
else:
last_seen_datetime = None
meta_result = {"id": row['id'],
"name": row['name'],
"uuid": row['uuid'],
"gateway": gateway_dict.get(row['gateway_id']),
"protocol": row['protocol'],
"connection": row['connection'],
"last_seen_datetime":
row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc).timestamp()*1000
if isinstance(row['last_seen_datetime_utc'], datetime) else None
"last_seen_datetime": last_seen_datetime
}
result.append(meta_result)
@ -192,15 +200,24 @@ class DataSourceItem:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.DATA_SOURCE_NOT_FOUND')
timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6])
if config.utc_offset[0] == '-':
timezone_offset = -timezone_offset
if isinstance(row['last_seen_datetime_utc'], datetime):
last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \
timedelta(minutes=timezone_offset)
last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
else:
last_seen_datetime = None
result = {"id": row['id'],
"name": row['name'],
"uuid": row['uuid'],
"gateway": gateway_dict.get(row['gateway_id']),
"protocol": row['protocol'],
"connection": row['connection'],
"last_seen_datetime":
row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc).timestamp()*1000
if isinstance(row['last_seen_datetime_utc'], datetime) else None
"last_seen_datetime": last_seen_datetime
}
resp.body = json.dumps(result)