Beispiel #1
0
 def _load_measurement_data(self, filename):
     with open(filename, 'r') as myf:
         fcsv = csv.reader(myf)
         header = fcsv.next()
         for line in fcsv:
             if line[0] == self.meter_id:
                 try:
                     ts = datetime.datetime.strptime(
                         line[1], '%Y-%m-%d %H:%M:%S')
                 except:
                     continue
                 tz = pytz.timezone('America/Jamaica')
                 ts = ts.replace(tzinfo=tz)
                 try:
                     dp = MeasurementDataPoint.objects.get(\
                       meter=self, ts=ts)
                 except:
                     dp = MeasurementDataPoint(\
                       meter=self, ts=ts)
                 for h, d in zip(header, line):
                     if h == 'DeviceId' or h == 'Code': pass
                     elif h == "Time Of Last Interrogation":
                         if d == '': continue
                         ts = datetime.datetime.strptime(
                             d, '%Y-%m-%d %H:%M:%S')
                         ts = ts.replace(tzinfo=tz)
                         dp.time_of_last_interrogation = ts
                     elif h == "Time Of Last Outage":
                         if d == '': continue
                         ts = datetime.datetime.strptime(
                             d, '%Y-%m-%d %H:%M:%S')
                         ts = ts.replace(tzinfo=tz)
                         dp.time_of_last_outage = ts
                     elif h == "Phase B Current angle":
                         dp.phase_b_current_angle = float(d)
                     elif h == "Daylight Savings Time Configured":
                         dp.daylight_savings_time_configured = True if d == 'True' else False
                     elif h == "Low Battery Error":
                         dp.low_battery_error = True if d == 'True' else False
                     elif h == "Metrology Communications Fatal Error":
                         dp.metrology_communications_fatal_error = True if d == 'True' else False
                     elif h == "Diagnostic Error (Inactive Phase)":
                         dp.inactive_phase = True if d == 'True' else False
                     elif h == "Diag Count 3":
                         dp.diag_count_3 = int(d)
                     elif h == "Diag Count 4":
                         dp.diag_count_4 = int(d)
                     elif h == "Times Programmed Count":
                         dp.times_programmed_count = int(d)
                     elif h == "Early Power Fail Count":
                         dp.early_power_fail_count = int(d)
                     elif h == "Good Battery Reading":
                         dp.good_battery_reading = int(d)
                     elif h == "File System Fatal Error":
                         dp.file_system_fatal_error = True if d == 'True' else False
                     elif h == "Diag Count 2":
                         dp.diag_count_2 = int(d)
                     elif h == "Phase A Current":
                         dp.phase_a_current = float(d)
                     elif h == "Phase A Current angle":
                         dp.phase_a_current_angle = float(d)
                     elif h == "ABC PHASE Rotation":
                         dp.abc_phase_rotation = int(d)
                     elif h == "Diagnostic Error (Voltage Deviation)":
                         dp.voltage_deviation = True if d == 'True' else False
                     elif h == "Diagnostic Error (Phase Angle Displacement)":
                         dp.phase_angle_displacement = True if d == 'True' else False
                     elif h == "Power Outage Count":
                         dp.power_outage_count = int(d)
                     elif h == "SLC Error":
                         dp.slc_error = True if d == 'True' else False
                     elif h == "Phase B Voltage":
                         dp.phase_b_voltage = float(d)
                     elif h == "Phase B Voltage angle":
                         dp.phase_b_voltage_angle = float(d)
                     elif h == "Phase C Voltage angle":
                         dp.phase_c_voltage_angle = float(d)
                     elif h == "Phase C Current angle":
                         dp.phase_c_current_angle = float(d)
                     elif h == "Phase A DC Detect":
                         dp.phase_a_dc_detect = float(d)
                     elif h == "Demand Reset Count":
                         dp.demand_reset_count = int(d)
                     elif h == "TOU Schedule Error":
                         dp.tou_schedule_error = True if d == 'True' else False
                     elif h == "Reverse Power Flow Error":
                         dp.reverse_power_flow_error = True if d == 'True' else False
                     elif h == "Diag 5 Phase B Count":
                         dp.diag_5_phase_b_count = int(d)
                     elif h == "Demand Interval Length":
                         dp.demand_interval_length = int(d)
                     elif h == "Phase B DC Detect":
                         dp.phase_b_dc_detect = float(d)
                     elif h == "Register Full Scale Exceeded Error":
                         dp.register_full_scale_exceeded_error = True if d == 'True' else False
                     elif h == "EPF Data Fatal Error":
                         dp.epf_data_fatal_error = True if d == 'True' else False
                     elif h == "Phase A Voltage":
                         dp.phase_a_voltage = float(d)
                     elif h == "Phase B Current":
                         dp.phase_b_current = float(d)
                     elif h == "Phase C Current":
                         dp.phase_c_current = float(d)
                     elif h == "Current Battery Reading":
                         dp.current_battery_reading = int(d)
                     elif h == "Demand Threshold Exceeded Error":
                         dp.demand_threshold_exceeded_error = True if d == 'True' else False
                     elif h == "Metrology Communications Error":
                         dp.metrology_communications_error = True if d == 'True' else False
                     elif h == "RAM Fatal Error":
                         dp.ram_fatal_error = True if d == 'True' else False
                     elif h == "Diag 5 Phase A Count":
                         dp.diag_5_phase_a_count = int(d)
                     elif h == "Diag 5 Phase C Count":
                         dp.diag_5_phase_c_count = int(d)
                     elif h == "Current Season":
                         dp.current_season = int(d)
                     elif h == "Phase C DC Detect":
                         dp.phase_c_dc_detect = float(d)
                     elif h == "Days Since Demand Reset":
                         dp.days_since_demand_reset = int(d)
                     elif h == "Days Since Last Test":
                         dp.days_since_last_test = int(d)
                     elif h == "Days On Battery":
                         dp.days_on_battery = int(d)
                     elif h == "Phase Loss Error":
                         dp.phase_loss_error = True if d == 'True' else False
                     elif h == "Mass Memory Error":
                         dp.mass_memory_error = True if d == 'True' else False
                     elif h == "Diagnostic Error (Cross Phase Flow)":
                         dp.cross_phase_flow = True if d == 'True' else False
                     elif h == "Diagnostic Error (Current Waveform Distorsion)":
                         dp.current_waveform_distorsion = True if d == 'True' else False
                     elif h == "Phase C Voltage":
                         dp.phase_c_voltage = float(d)
                     elif h == "Service Type Detected":
                         dp.service_type_detected = int(d)
                     elif h == "MCU Flash Fatal Error":
                         dp.mcu_flash_fatal_error = True if d == 'True' else False
                     elif h == "Data Flash Fatal Error":
                         dp.data_flash_fatal_error = True if d == 'True' else False
                     elif h == "Diag Count 1":
                         dp.diag_count_1 = int(d)
                     elif h == "Diag Count 5":
                         dp.diag_count_5 = int(d)
                     elif h == "Clock Sync Error":
                         dp.clock_sync_error = True if d == 'True' else False
                     elif h == "Site Scan Error":
                         dp.site_scan_error = True if d == 'True' else False
                     else:
                         print 'XXX ' + h + ' unrecognized'
                 dp.save()
     return True
Beispiel #2
0
 def _load_measurement_data(self, filename):
     with open(filename, "r") as myf:
         fcsv = csv.reader(myf)
         header = fcsv.next()
         for line in fcsv:
             if line[0] == self.meter_id:
                 try:
                     ts = datetime.datetime.strptime(line[1], "%Y-%m-%d %H:%M:%S")
                 except:
                     continue
                 tz = pytz.timezone("America/Jamaica")
                 ts = ts.replace(tzinfo=tz)
                 try:
                     dp = MeasurementDataPoint.objects.get(meter=self, ts=ts)
                 except:
                     dp = MeasurementDataPoint(meter=self, ts=ts)
                 for h, d in zip(header, line):
                     if h == "DeviceId" or h == "Code":
                         pass
                     elif h == "Time Of Last Interrogation":
                         if d == "":
                             continue
                         ts = datetime.datetime.strptime(d, "%Y-%m-%d %H:%M:%S")
                         ts = ts.replace(tzinfo=tz)
                         dp.time_of_last_interrogation = ts
                     elif h == "Time Of Last Outage":
                         if d == "":
                             continue
                         ts = datetime.datetime.strptime(d, "%Y-%m-%d %H:%M:%S")
                         ts = ts.replace(tzinfo=tz)
                         dp.time_of_last_outage = ts
                     elif h == "Phase B Current angle":
                         dp.phase_b_current_angle = float(d)
                     elif h == "Daylight Savings Time Configured":
                         dp.daylight_savings_time_configured = True if d == "True" else False
                     elif h == "Low Battery Error":
                         dp.low_battery_error = True if d == "True" else False
                     elif h == "Metrology Communications Fatal Error":
                         dp.metrology_communications_fatal_error = True if d == "True" else False
                     elif h == "Diagnostic Error (Inactive Phase)":
                         dp.inactive_phase = True if d == "True" else False
                     elif h == "Diag Count 3":
                         dp.diag_count_3 = int(d)
                     elif h == "Diag Count 4":
                         dp.diag_count_4 = int(d)
                     elif h == "Times Programmed Count":
                         dp.times_programmed_count = int(d)
                     elif h == "Early Power Fail Count":
                         dp.early_power_fail_count = int(d)
                     elif h == "Good Battery Reading":
                         dp.good_battery_reading = int(d)
                     elif h == "File System Fatal Error":
                         dp.file_system_fatal_error = True if d == "True" else False
                     elif h == "Diag Count 2":
                         dp.diag_count_2 = int(d)
                     elif h == "Phase A Current":
                         dp.phase_a_current = float(d)
                     elif h == "Phase A Current angle":
                         dp.phase_a_current_angle = float(d)
                     elif h == "ABC PHASE Rotation":
                         dp.abc_phase_rotation = int(d)
                     elif h == "Diagnostic Error (Voltage Deviation)":
                         dp.voltage_deviation = True if d == "True" else False
                     elif h == "Diagnostic Error (Phase Angle Displacement)":
                         dp.phase_angle_displacement = True if d == "True" else False
                     elif h == "Power Outage Count":
                         dp.power_outage_count = int(d)
                     elif h == "SLC Error":
                         dp.slc_error = True if d == "True" else False
                     elif h == "Phase B Voltage":
                         dp.phase_b_voltage = float(d)
                     elif h == "Phase B Voltage angle":
                         dp.phase_b_voltage_angle = float(d)
                     elif h == "Phase C Voltage angle":
                         dp.phase_c_voltage_angle = float(d)
                     elif h == "Phase C Current angle":
                         dp.phase_c_current_angle = float(d)
                     elif h == "Phase A DC Detect":
                         dp.phase_a_dc_detect = float(d)
                     elif h == "Demand Reset Count":
                         dp.demand_reset_count = int(d)
                     elif h == "TOU Schedule Error":
                         dp.tou_schedule_error = True if d == "True" else False
                     elif h == "Reverse Power Flow Error":
                         dp.reverse_power_flow_error = True if d == "True" else False
                     elif h == "Diag 5 Phase B Count":
                         dp.diag_5_phase_b_count = int(d)
                     elif h == "Demand Interval Length":
                         dp.demand_interval_length = int(d)
                     elif h == "Phase B DC Detect":
                         dp.phase_b_dc_detect = float(d)
                     elif h == "Register Full Scale Exceeded Error":
                         dp.register_full_scale_exceeded_error = True if d == "True" else False
                     elif h == "EPF Data Fatal Error":
                         dp.epf_data_fatal_error = True if d == "True" else False
                     elif h == "Phase A Voltage":
                         dp.phase_a_voltage = float(d)
                     elif h == "Phase B Current":
                         dp.phase_b_current = float(d)
                     elif h == "Phase C Current":
                         dp.phase_c_current = float(d)
                     elif h == "Current Battery Reading":
                         dp.current_battery_reading = int(d)
                     elif h == "Demand Threshold Exceeded Error":
                         dp.demand_threshold_exceeded_error = True if d == "True" else False
                     elif h == "Metrology Communications Error":
                         dp.metrology_communications_error = True if d == "True" else False
                     elif h == "RAM Fatal Error":
                         dp.ram_fatal_error = True if d == "True" else False
                     elif h == "Diag 5 Phase A Count":
                         dp.diag_5_phase_a_count = int(d)
                     elif h == "Diag 5 Phase C Count":
                         dp.diag_5_phase_c_count = int(d)
                     elif h == "Current Season":
                         dp.current_season = int(d)
                     elif h == "Phase C DC Detect":
                         dp.phase_c_dc_detect = float(d)
                     elif h == "Days Since Demand Reset":
                         dp.days_since_demand_reset = int(d)
                     elif h == "Days Since Last Test":
                         dp.days_since_last_test = int(d)
                     elif h == "Days On Battery":
                         dp.days_on_battery = int(d)
                     elif h == "Phase Loss Error":
                         dp.phase_loss_error = True if d == "True" else False
                     elif h == "Mass Memory Error":
                         dp.mass_memory_error = True if d == "True" else False
                     elif h == "Diagnostic Error (Cross Phase Flow)":
                         dp.cross_phase_flow = True if d == "True" else False
                     elif h == "Diagnostic Error (Current Waveform Distorsion)":
                         dp.current_waveform_distorsion = True if d == "True" else False
                     elif h == "Phase C Voltage":
                         dp.phase_c_voltage = float(d)
                     elif h == "Service Type Detected":
                         dp.service_type_detected = int(d)
                     elif h == "MCU Flash Fatal Error":
                         dp.mcu_flash_fatal_error = True if d == "True" else False
                     elif h == "Data Flash Fatal Error":
                         dp.data_flash_fatal_error = True if d == "True" else False
                     elif h == "Diag Count 1":
                         dp.diag_count_1 = int(d)
                     elif h == "Diag Count 5":
                         dp.diag_count_5 = int(d)
                     elif h == "Clock Sync Error":
                         dp.clock_sync_error = True if d == "True" else False
                     elif h == "Site Scan Error":
                         dp.site_scan_error = True if d == "True" else False
                     else:
                         print "XXX " + h + " unrecognized"
                 dp.save()
     return True
Beispiel #3
0
    def _load_measurement_data_mv90(self, row=None):
        d = None
        if row is None:
            con = pyodbc.connect(servername='mv90',
                                 user=os.environ['MV90_USER'],
                                 password=os.environ['MV90_PASS'],
                                 driver='FreeTDS',
                                 database='MR-Auxillary')
            cur = con.cursor()
            cur.execute(
                'SELECT TOP 1 * FROM MeterExtras WHERE MeterNumber=? ORDER BY ReadingTime DESC',
                (self.meter_id, ))
            d = cur.fetchall()
            if len(d) == 0: return
            d = d[0]
        else:
            d = row
        ts = datetime.datetime.strptime(d[3].split('.')[0],
                                        '%Y-%m-%d %H:%M:%S')
        tz = pytz.timezone('America/Jamaica')
        tzutc = pytz.timezone('UTC')
        ts = ts.replace(tzinfo=tzutc)
        ts = ts.astimezone(tz)
        try:
            dp = MeasurementDataPoint.objects.get(\
              meter=self, ts=ts)
        except:
            dp = MeasurementDataPoint(\
              meter=self, ts=ts)
        [
            Id, RecordSource, MeterNumber, ReadingTime, demandInterval,
            numberOfDemandResets, demandResetDateTime, numberOfPwrOutages,
            dateTimeLastPwrOutage, numberOfTimesProgrammed, dateLastProgrammed,
            diagnostic1, diagnostic2, diagnostic3, diagnostic4, diagnostic5,
            diagnostic6, diag5PhaseA, diag5PhaseB, diag5PhaseC,
            CSphaseAInstVolts, CSphaseBInstVolts, CSphaseCInstVolts,
            CSphaseAInstAmps, CSphaseBInstAmps, CSphaseCInstAmps,
            voltageAnglePhaseB, voltageAnglePhaseC, currentAnglePhaseA,
            currentAnglePhaseB, currentAnglePhaseC
        ] = d
        dp.phase_a_voltage = CSphaseAInstVolts
        dp.phase_b_voltage = CSphaseBInstVolts
        dp.phase_c_voltage = CSphaseCInstVolts
        dp.phase_a_current = CSphaseAInstAmps
        dp.phase_b_current = CSphaseBInstAmps
        dp.phase_c_current = CSphaseCInstAmps
        dp.phase_a_current_angle = currentAnglePhaseA
        dp.phase_b_current_angle = currentAnglePhaseB
        dp.phase_c_current_angle = currentAnglePhaseC
        dp.phase_b_voltage_angle = voltageAnglePhaseB
        dp.phase_c_voltage_angle = voltageAnglePhaseC

        dp.demand_reset_count = numberOfDemandResets
        dp.power_outage_count = numberOfPwrOutages
        dp.diag_count_1 = diagnostic1
        dp.diag_count_2 = diagnostic2
        dp.diag_count_3 = diagnostic3
        dp.diag_count_4 = diagnostic4
        dp.diag_count_5 = diagnostic5
        dp.diag_count_6 = diagnostic6
        dp.diag_5_phase_a_count = diag5PhaseA
        dp.diag_5_phase_b_count = diag5PhaseB
        dp.diag_5_phase_c_count = diag5PhaseC
        dp.save()
Beispiel #4
0
    def _load_measurement_data_mv90(self, row=None):
        d = None
        if row is None:
            con = pyodbc.connect(
                servername="mv90",
                user=os.environ["MV90_USER"],
                password=os.environ["MV90_PASS"],
                driver="FreeTDS",
                database="MR-Auxillary",
            )
            cur = con.cursor()
            cur.execute(
                "SELECT TOP 1 * FROM MeterExtras WHERE MeterNumber=? ORDER BY ReadingTime DESC", (self.meter_id,)
            )
            d = cur.fetchall()
            if len(d) == 0:
                return
            d = d[0]
        else:
            d = row
        ts = datetime.datetime.strptime(d[3].split(".")[0], "%Y-%m-%d %H:%M:%S")
        tz = pytz.timezone("America/Jamaica")
        tzutc = pytz.timezone("UTC")
        ts = ts.replace(tzinfo=tzutc)
        ts = ts.astimezone(tz)
        try:
            dp = MeasurementDataPoint.objects.get(meter=self, ts=ts)
        except:
            dp = MeasurementDataPoint(meter=self, ts=ts)
        [
            Id,
            RecordSource,
            MeterNumber,
            ReadingTime,
            demandInterval,
            numberOfDemandResets,
            demandResetDateTime,
            numberOfPwrOutages,
            dateTimeLastPwrOutage,
            numberOfTimesProgrammed,
            dateLastProgrammed,
            diagnostic1,
            diagnostic2,
            diagnostic3,
            diagnostic4,
            diagnostic5,
            diagnostic6,
            diag5PhaseA,
            diag5PhaseB,
            diag5PhaseC,
            CSphaseAInstVolts,
            CSphaseBInstVolts,
            CSphaseCInstVolts,
            CSphaseAInstAmps,
            CSphaseBInstAmps,
            CSphaseCInstAmps,
            voltageAnglePhaseB,
            voltageAnglePhaseC,
            currentAnglePhaseA,
            currentAnglePhaseB,
            currentAnglePhaseC,
        ] = d
        dp.phase_a_voltage = CSphaseAInstVolts
        dp.phase_b_voltage = CSphaseBInstVolts
        dp.phase_c_voltage = CSphaseCInstVolts
        dp.phase_a_current = CSphaseAInstAmps
        dp.phase_b_current = CSphaseBInstAmps
        dp.phase_c_current = CSphaseCInstAmps
        dp.phase_a_current_angle = currentAnglePhaseA
        dp.phase_b_current_angle = currentAnglePhaseB
        dp.phase_c_current_angle = currentAnglePhaseC
        dp.phase_b_voltage_angle = voltageAnglePhaseB
        dp.phase_c_voltage_angle = voltageAnglePhaseC

        dp.demand_reset_count = numberOfDemandResets
        dp.power_outage_count = numberOfPwrOutages
        dp.diag_count_1 = diagnostic1
        dp.diag_count_2 = diagnostic2
        dp.diag_count_3 = diagnostic3
        dp.diag_count_4 = diagnostic4
        dp.diag_count_5 = diagnostic5
        dp.diag_count_6 = diagnostic6
        dp.diag_5_phase_a_count = diag5PhaseA
        dp.diag_5_phase_b_count = diag5PhaseB
        dp.diag_5_phase_c_count = diag5PhaseC
        dp.save()