def get_all_devices_consumption_that_day():
    devices = data_service.get_electric_consumption_devices()

    all_time = list(data_service.time_range)
    all_cons_map = dict.fromkeys(all_time, 0)

    for device_name, device_entity in devices.items():
        # device_time = list(get_usage_times(device_name))
        intersected_map_of_usage = intersected_map_of_device_usage(
            device_entity)
        for t, Wt in intersected_map_of_usage.items():
            # if t in device_time:
            all_cons_map[t] += intersected_map_of_usage[t]
    # print("AALLLLLL", all_cons_map.values())
    return all_cons_map
def animate_2_1_2_graph(i):
    is_active = data_service.get_active()
    print("a", is_active)
    if is_active == "2_1_2":
        all_devices = data_service.get_electric_consumption_devices()
        intersected_map = tab2_service.intersected_map_of_device_usage(
            all_devices["cooker"])
        # date = [item.date() for item in xs]

        xs = list(intersected_map.keys())
        ys = list(intersected_map.values())
        _2_1_2_graph_ax.clear()
        _2_1_2_graph_ax.set(xlabel='час (вісь Х)',
                            ylabel='W, Вт',
                            title='Графік навантаження плити')
        _2_1_2_graph_ax.grid()
        width = np.min(np.diff(mdates.date2num(xs)))
        # Define the date format
        date_form = DateFormatter("%H:%M")
        _2_1_2_graph_ax.xaxis.set_major_formatter(date_form)
        # Ensure ticks fall once every other week (interval=2)
        _2_1_2_graph_ax.xaxis.set_major_locator(mdates.HourLocator(interval=2))

        _2_1_2_graph_ax.bar(xs, ys, width=width, ec="k")
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        button_to_main = tk.Button(
            self,
            text="на головну",
            width=40,
            command=lambda: data_service.display_graph_and_set_active(
                controller, router.WelcomePage, "DISABLED"))
        button_to_main.pack()
        button_go_back = tk.Button(
            self,
            text="назад",
            width=40,
            command=lambda: data_service.display_graph_and_set_active(
                controller, Tab2Page, "DISABLED"))
        button_go_back.pack()

        name_of_device = tk.StringVar()
        ent_name_of_device = tk.Entry(self, textvariable=name_of_device)
        ent_name_of_device.insert(0, data_service.get_cur_device())

        list_usage = tk.StringVar()
        ent_list_usage = tk.Entry(self, textvariable=list_usage)
        ent_list_usage.insert(
            0, ','.join(data_service.get_electric_consumption_devices()[
                data_service.get_cur_device()].week_list[
                    data_service.get_cur_day_of_week()]))

        day_of_week = tk.StringVar()
        ent_day_of_week = tk.Entry(self, textvariable=day_of_week)
        ent_day_of_week.insert(0, data_service.get_cur_day_of_week())

        label = tk.Label(
            self,
            text=("""\nНазва приладу:(""", ','.join(
                list(data_service.get_electric_consumption_devices().keys())),
                  ")"),
            font=my_view.CONSOLE_FONT_12)

        label.configure(background='black', foreground='green')
        label.pack(pady=3, padx=3)
        ent_name_of_device.pack()

        label = tk.Label(
            self,
            text=
            ("""\nДень використання:("Mn", "Tu", "Wd", "Th", "Fr", "Sa", "Sn")"""
             ),
            font=my_view.CONSOLE_FONT_12)
        label.configure(background='black', foreground='green')
        label.pack(pady=3, padx=3)
        ent_day_of_week.pack()

        label = tk.Label(
            self,
            text=
            ("""\nГодини використання:(через кому або "fulltime" - для повного дня)"""
             ),
            font=my_view.CONSOLE_FONT_12)
        label.configure(background='black', foreground='green')
        label.pack(pady=3, padx=3)
        ent_list_usage.pack()

        btn1 = tk.Button(
            self,
            text="OK",
            width=10,
            bg='lightgreen',
            fg='blue',
            relief='flat',
            bd=10,
            highlightthickness=4,
            highlightcolor="#37d3ff",
            highlightbackground="#37d3ff",
            borderwidth=4,
            command=lambda: data_service.set_time_for_certain_device(
                day_of_week.get(), name_of_device.get(),
                list_usage.get().split(',').copy()))
        btn1.pack(padx=5, pady=5)
def sum_all_W_from_devices():
    sum_all = 0
    for k, v in data_service.get_electric_consumption_devices().items():
        sum_all += v.consum_power
    return sum_all