Code Duplication    Length = 31-31 lines in 2 locations

myems-api/reports/energystoragepowerstationdetailsschedule.py 1 location

@@ 97-127 (lines=31) @@
94
                              " ORDER BY start_time_of_day ",
95
                              (container_list[0]['id'],))
96
        rows_schedules = cursor_system.fetchall()
97
        if rows_schedules is None or len(rows_schedules) == 0:
98
            pass
99
        else:
100
            for row_schedule in rows_schedules:
101
                start_time = row_schedule[0]
102
                end_time = row_schedule[1]
103
                current_time = start_time
104
                if row_schedule[2] == 'toppeak':
105
                    peak_type = 'Top-Peak'
106
                elif row_schedule[2] == 'onpeak':
107
                    peak_type = 'On-Peak'
108
                elif row_schedule[2] == 'midpeak':
109
                    peak_type = 'Mid-Peak'
110
                elif row_schedule[2] == 'offpeak':
111
                    peak_type = 'Off-Peak'
112
                elif row_schedule[2] == 'deep':
113
                    peak_type = 'Deep-Valley'
114
                else:
115
                    peak_type = 'Unknown'
116
117
                while current_time < end_time:
118
                    schedule_series_data.append(row_schedule[3])
119
                    current_time = current_time + timedelta(minutes=30)
120
121
                schedule_list.append({"start_time_of_day": '0' + str(start_time) if len(str(start_time)) == 7
122
                                      else str(start_time),
123
                                      "end_time_of_day": '0' + str(end_time) if len(str(end_time)) == 7
124
                                      else str(end_time),
125
                                      "peak_type": peak_type,
126
                                      "power": row_schedule[3]})
127
            print('schedule_list:' + str(schedule_list))
128
129
        if cursor_system:
130
            cursor_system.close()

myems-api/reports/microgriddetails.py 1 location

@@ 602-632 (lines=31) @@
599
                              " ORDER BY start_time_of_day ",
600
                              (microgrid_id,))
601
        rows_schedules = cursor_system.fetchall()
602
        if rows_schedules is None or len(rows_schedules) == 0:
603
            pass
604
        else:
605
            for row_schedule in rows_schedules:
606
                start_time = row_schedule[0]
607
                end_time = row_schedule[1]
608
                current_time = start_time
609
                if row_schedule[2] == 'toppeak':
610
                    peak_type = 'Top-Peak'
611
                elif row_schedule[2] == 'onpeak':
612
                    peak_type = 'On-Peak'
613
                elif row_schedule[2] == 'midpeak':
614
                    peak_type = 'Mid-Peak'
615
                elif row_schedule[2] == 'offpeak':
616
                    peak_type = 'Off-Peak'
617
                elif row_schedule[2] == 'deep':
618
                    peak_type = 'Deep-Valley'
619
                else:
620
                    peak_type = 'Unknown'
621
622
                while current_time < end_time:
623
                    schedule_series_data.append(row_schedule[3])
624
                    current_time = current_time + timedelta(minutes=30)
625
626
                schedule_list.append({"start_time_of_day": '0' + str(start_time) if len(str(start_time)) == 7
627
                                     else str(start_time),
628
                                      "end_time_of_day": '0' + str(end_time) if len(str(end_time)) == 7
629
                                      else str(end_time),
630
                                      "peak_type": peak_type,
631
                                      "power": row_schedule[3]})
632
            print('schedule_list:' + str(schedule_list))
633
        ################################################################################################################
634
        # Step 12: query associated sensors
635
        ################################################################################################################