update : 14.01.2025 17:34:00,97
This commit is contained in:
parent
1b3c76a59f
commit
2f1b60a97e
@ -4,6 +4,7 @@ from .models.model_equipment import Equipment
|
||||
from .models.model_type_sensor import TypeSensor
|
||||
from .models.model_sensors import Sensors
|
||||
from .models.model_indicators import Indicators
|
||||
from .models.model_alarm import GtoAlarm
|
||||
|
||||
|
||||
@admin.register(Indicators)
|
||||
@ -27,4 +28,9 @@ class TypeSensorAdmin(admin.ModelAdmin):
|
||||
@admin.register(Equipment)
|
||||
class EquipmentAdmin(admin.ModelAdmin):
|
||||
ordering = ('name',)
|
||||
list_display = ('name','statenum','time','lat','lon','speed')
|
||||
list_display = ('name','statenum','time','lat','lon','speed')
|
||||
|
||||
@admin.register(GtoAlarm)
|
||||
class GtoAlarmAdmin(admin.ModelAdmin):
|
||||
ordering = ('equipment',)
|
||||
list_display = ('time','alarmid','equipment','lat','lon')
|
||||
38
apps/gto/migrations/0008_auto_20250114_1721.py
Normal file
38
apps/gto/migrations/0008_auto_20250114_1721.py
Normal file
@ -0,0 +1,38 @@
|
||||
# Generated by Django 3.2.16 on 2025-01-14 17:21
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('gto', '0007_equipment_full_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Alarm',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('alarmid', models.CharField(default=' ', max_length=36, verbose_name='ID аларма')),
|
||||
('equipment', models.CharField(default=' ', max_length=80, verbose_name='Объект')),
|
||||
('lat', models.FloatField(default=0.0, verbose_name='Широта')),
|
||||
('lon', models.FloatField(default=0.0, verbose_name='Долгота')),
|
||||
('time', models.DateTimeField(blank=True, verbose_name='Время события')),
|
||||
('alarm_type', models.CharField(blank=True, max_length=50, verbose_name='Тип события')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'событие',
|
||||
'verbose_name_plural': 'события',
|
||||
'ordering': ('alarmid',),
|
||||
},
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='alarm',
|
||||
index=models.Index(fields=['alarmid'], name='gto_alarm_alarmid_bb25e2_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='alarm',
|
||||
index=models.Index(fields=['equipment'], name='gto_alarm_equipme_0b7ee2_idx'),
|
||||
),
|
||||
]
|
||||
32
apps/gto/migrations/0009_auto_20250114_1726.py
Normal file
32
apps/gto/migrations/0009_auto_20250114_1726.py
Normal file
@ -0,0 +1,32 @@
|
||||
# Generated by Django 3.2.16 on 2025-01-14 17:26
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('gto', '0008_auto_20250114_1721'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveIndex(
|
||||
model_name='alarm',
|
||||
name='gto_alarm_equipme_0b7ee2_idx',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='alarm',
|
||||
name='alarmid',
|
||||
field=models.IntegerField(default=0, verbose_name='ID аларма'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='alarm',
|
||||
name='equipment',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='gto.equipment', verbose_name='Объект'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='alarm',
|
||||
index=models.Index(fields=['equipment'], name='gto_alarm_equipme_1348f0_idx'),
|
||||
),
|
||||
]
|
||||
33
apps/gto/migrations/0010_auto_20250114_1728.py
Normal file
33
apps/gto/migrations/0010_auto_20250114_1728.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Generated by Django 3.2.16 on 2025-01-14 17:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('gto', '0009_auto_20250114_1726'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name='Alarm',
|
||||
new_name='GtoAlarm',
|
||||
),
|
||||
migrations.RemoveIndex(
|
||||
model_name='gtoalarm',
|
||||
name='gto_alarm_alarmid_bb25e2_idx',
|
||||
),
|
||||
migrations.RemoveIndex(
|
||||
model_name='gtoalarm',
|
||||
name='gto_alarm_equipme_1348f0_idx',
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='gtoalarm',
|
||||
index=models.Index(fields=['alarmid'], name='gto_gtoalar_alarmid_a195d2_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='gtoalarm',
|
||||
index=models.Index(fields=['equipment'], name='gto_gtoalar_equipme_bb01e5_idx'),
|
||||
),
|
||||
]
|
||||
52
apps/gto/models/model_alarm.py
Normal file
52
apps/gto/models/model_alarm.py
Normal file
@ -0,0 +1,52 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django.db import models
|
||||
from django.urls import reverse #Used to generate URLs by reversing the URL patterns
|
||||
|
||||
from apps.gto.models.model_equipment import Equipment
|
||||
|
||||
class GtoAlarm(models.Model): # События
|
||||
|
||||
alarmid = models.IntegerField(help_text="",
|
||||
default=0,
|
||||
verbose_name="ID аларма")
|
||||
equipment = models.ForeignKey(Equipment,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
verbose_name="Объект")
|
||||
lat = models.FloatField(default=0.0,
|
||||
help_text="",
|
||||
verbose_name="Широта")
|
||||
lon = models.FloatField(default=0.0,
|
||||
help_text="",
|
||||
verbose_name="Долгота")
|
||||
time = models.DateTimeField(auto_now=False,
|
||||
auto_now_add=False,
|
||||
blank=True,
|
||||
verbose_name="Время события")
|
||||
alarm_type = models.CharField(max_length=50,
|
||||
blank=True, verbose_name=u'Тип события')
|
||||
|
||||
|
||||
def getLat(self):
|
||||
return str(self.lat).replace(',','.')
|
||||
|
||||
def getLon(self):
|
||||
return str(self.lon).replace(',','.')
|
||||
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
String for representing the Model object (in Admin site etc.)
|
||||
"""
|
||||
return self.name
|
||||
|
||||
class Meta: # отображение в админики
|
||||
ordering = ('alarmid',)
|
||||
verbose_name = u'событие'
|
||||
verbose_name_plural = u'события'
|
||||
indexes = [
|
||||
models.Index(fields=['alarmid',]),
|
||||
models.Index(fields=['equipment',]),
|
||||
]
|
||||
|
||||
|
||||
@ -393,9 +393,9 @@ def load_edds():
|
||||
full_name="" if data[2] is None else data[2]
|
||||
|
||||
element = Equipment.objects.create(uid=data[0],
|
||||
name="" if data[1] is None else data[1],
|
||||
full_name="" if data[2] is None else data[2],
|
||||
time=datetime.now() if data[3] is None else data[3]+ timedelta(hours=7))
|
||||
name="" if data[1] is None else data[1],
|
||||
full_name="" if data[2] is None else data[2],
|
||||
time=datetime.now() if data[3] is None else data[3]+ timedelta(hours=7))
|
||||
else:
|
||||
element.name="" if data[1] is None else data[1]
|
||||
element.full_name="" if data[2] is None else data[2]
|
||||
@ -411,33 +411,33 @@ def load_edds():
|
||||
element.lon = 0 if row[3] is None else row[3]
|
||||
element.speed = 0 if row[5] is None else row[5]
|
||||
add_sensor(type_code=1,
|
||||
type_name="Датчик спутников",
|
||||
equipment =element,
|
||||
sensor_id = 1,
|
||||
sensor_name = 'Количество спутников',
|
||||
sensor_time=row[0],
|
||||
sensor_value=0 if isinstance(row[6], bytes) else row[6])
|
||||
type_name="Датчик спутников",
|
||||
equipment =element,
|
||||
sensor_id = 1,
|
||||
sensor_name = 'Количество спутников',
|
||||
sensor_time=row[0],
|
||||
sensor_value=0 if isinstance(row[6], bytes) else row[6])
|
||||
add_sensor(type_code=2,
|
||||
type_name="Питание",
|
||||
equipment =element,
|
||||
sensor_id = 2,
|
||||
sensor_name = 'Питание терминала',
|
||||
sensor_time=row[0],
|
||||
sensor_value=row[7])
|
||||
type_name="Питание",
|
||||
equipment =element,
|
||||
sensor_id = 2,
|
||||
sensor_name = 'Питание терминала',
|
||||
sensor_time=row[0],
|
||||
sensor_value=row[7])
|
||||
add_sensor(type_code=3,
|
||||
type_name="Напряжение",
|
||||
equipment =element,
|
||||
sensor_id = 3,
|
||||
sensor_name = 'Напряжение внутреннего аккумулятора терминала',
|
||||
sensor_time=row[0],
|
||||
sensor_value=row[8])
|
||||
type_name="Напряжение",
|
||||
equipment =element,
|
||||
sensor_id = 3,
|
||||
sensor_name = 'Напряжение внутреннего аккумулятора терминала',
|
||||
sensor_time=row[0],
|
||||
sensor_value=row[8])
|
||||
add_sensor(type_code=4,
|
||||
type_name="Датчик высоты",
|
||||
equipment =element,
|
||||
sensor_id = 4,
|
||||
sensor_name = 'Высота',
|
||||
sensor_time=row[0],
|
||||
sensor_value=row[4])
|
||||
type_name="Датчик высоты",
|
||||
equipment =element,
|
||||
sensor_id = 4,
|
||||
sensor_name = 'Высота',
|
||||
sensor_time=row[0],
|
||||
sensor_value=row[4])
|
||||
element.save()
|
||||
return None
|
||||
except Exception as err:
|
||||
@ -547,9 +547,23 @@ def load_asd():
|
||||
element.lon = lat
|
||||
element.speed = speed
|
||||
element.save()
|
||||
|
||||
|
||||
sql_query = """
|
||||
SELECT * FROM MFSB.TRUCKALARMS
|
||||
"""
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(sql_query)
|
||||
for data in cursor:
|
||||
pass
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return None
|
||||
except Exception as err:
|
||||
logging.error(traceback.format_exc())
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
@app.task()
|
||||
def load_navigation(): #
|
||||
|
||||
6
start.py
6
start.py
@ -99,7 +99,7 @@ def test_oracle_connect():
|
||||
|
||||
connection = cx_Oracle.connect('mfsb/00QgSiB1@192.168.77.1:1521/v3')
|
||||
cursor = connection.cursor()
|
||||
sql='SELECT * FROM MFSB.OBJSTATE'
|
||||
sql='SELECT * FROM MFSB.TRUCKALARMS'
|
||||
#sql='SELECT owner, table_name FROM dba_tables'
|
||||
#sql='SELECT owner,table_name FROM all_tables'
|
||||
cursor.execute(sql)
|
||||
@ -118,5 +118,5 @@ if __name__ == "__main__":
|
||||
#Indicators.objects.all().delete()
|
||||
#Sensors.objects.all().delete()
|
||||
|
||||
tasks.load_navigation()
|
||||
#test_oracle_connect()
|
||||
#tasks.load_navigation()
|
||||
test_oracle_connect()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user