示例#1
0
def main():
    db_conn = create_sqlite3_connection()
    cursor = db_conn.cursor()
    data = energy_data.get_data()

    if data is not None:
        try:
            sql = "INSERT INTO energy (production, import, export, power_production, power_import, power_export, production_deye, power_production_deye) \
                VALUES (?, ?, ?, ?, ?, ?, ?, ?)"

            cursor.execute(sql, (
                data['energy_flara'],
                data['total_energy_import'],
                data['total_energy_export'],
                data['power_flara'],
                data['power_import'],
                data['power_export'],
                data['energy_deye'],
                data['power_deye'],
            ))
            db_conn.commit()
        except Error as e:
            print(e)

        cursor.close()
        db_conn.close()
示例#2
0
def main():
    db_conn = create_sqlite3_connection()
    cursor = db_conn.cursor()
    data = meteo_data.get_data()

    if data is not None and data['is_data_correct']:
        try:
            sql = "INSERT INTO meteo (temperature, humidity, pressure, dust_PM10, dust_PM25, dust_PM100) \
                VALUES (?, ?, ?, ?, ?, ?)"

            cursor.execute(
                sql,
                (data['temperature'], data['humidity'], data['pressure'],
                 data['dust_PM10'], data['dust_PM25'], data['dust_PM100']))
            db_conn.commit()
        except Error as e:
            print(e)

        cursor.close()
        db_conn.close()
示例#3
0
def main():
    db_conn = create_sqlite3_connection()
    cursor = db_conn.cursor()

    if len(sys.argv) != 3:
        print("Usage: [date in format {}] [correction]".format(
            datetime.date.today().isoformat()))
        return

    date = sys.argv[1]
    val = int(float(sys.argv[2]) * 1000)

    try:
        sql = "INSERT INTO energy_corrections (date, correction) \
            VALUES (?, ?)"

        cursor.execute(sql, (date, val))
        db_conn.commit()
    except Error as e:
        print(e)

    cursor.close()
    db_conn.close()
示例#4
0
def main():
    db_con = create_sqlite3_connection()
    last = db_con.execute(sql_select_energy_daily).fetchone()

    last_production_offset = last_production_deye_offset = last_import_offset = last_export_offset = 0
    if last is not None:
        start_day = last[0] + 1
        tajm = datetime.combine(date.fromordinal(start_day), time())
        energy_data = db_con.execute(sql_select_energy,
                                     (tajm.timestamp(), )).fetchall()
        last_production_offset = last[1]
        last_import_offset = last[2]
        last_export_offset = last[3]
        last_production_deye_offset = last[4]
    else:
        energy_data = db_con.execute(sql_select_energy, (0, )).fetchall()
        start_day = datetime.fromtimestamp(
            energy_data[0][1]).date().toordinal()

    print("Zaczynamy od ", str(date.fromordinal(start_day)))

    days = {}
    for x in range(start_day, date.today().toordinal()):
        days[x] = []

    for entry in energy_data:
        day_number = datetime.fromtimestamp(entry[1]).date().toordinal()
        if day_number in days:
            days[day_number].append(entry)

    for day, datas in sorted(days.items()):
        max_power_production = 0
        max_power_import = 0
        max_power_export = 0
        max_power_consumption = 0
        max_power_use = 0
        max_power_store = 0
        for entry in datas:
            id, dat, prod, imp, exp, power_production, power_import, power_export, production_deye, power_production_deye = entry
            total_power_prod = power_production + power_production_deye
            max_power_production = max(max_power_production, total_power_prod)
            max_power_import = max(max_power_import, power_import)
            max_power_export = max(max_power_export, power_export)
            max_power_consumption = max(
                max_power_consumption,
                power_import + total_power_prod - power_export)
            max_power_use = max(max_power_use, total_power_prod - power_export)
            max_power_store = int(
                max(max_power_store, power_export * 0.8 - power_import))

        production = production_deye = import_ = export = 0
        if datas:
            production = datas[-1][2] - datas[0][2]
            production_deye = datas[-1][8] - datas[0][8]
            import_ = datas[-1][3] - datas[0][3]
            export = datas[-1][4] - datas[0][4]
            last_production_offset = datas[-1][2]
            last_import_offset = datas[-1][3]
            last_export_offset = datas[-1][4]
            last_production_deye_offset = datas[-1][8]

        print(
            "[Dzien {}] pomiarow: {}, produkcja: {}, produkcja deye: {}, import: {}, export: {}"
            .format(str(date.fromordinal(day)), len(datas), production,
                    production_deye, import_, export))

        db_con.execute(
            sql_insert_daily,
            (day, production, import_, export, last_production_offset,
             last_import_offset, last_export_offset, max_power_production,
             max_power_import, max_power_export, max_power_consumption,
             max_power_use, max_power_store, production_deye,
             last_production_deye_offset))

    db_con.commit()
    db_con.close()
示例#5
0
    sun = loc.sun(date=day)
    hours[1] = sun['dawn']
    hours[2] = sun['sunrise']
    hours[3] = sun['noon']
    hours[4] = sun['sunset']
    hours[5] = sun['dusk']
    hours[6] = datetime.datetime.combine(day, datetime.time())
    return hours


today = datetime.date.today()
todayHours = calcHours(today)
tommorowHours = calcHours(today + datetime.timedelta(days=1))

conn = create_sqlite3_connection()
try:
    cur = conn.cursor()
    cur.execute(
        "SELECT id, device, action, hour_type, time_offset FROM blinds_schedule"
    )

    schedules = cur.fetchall()

    for sched in schedules:
        sched_id, device_id, action_id, hour_type, time_offset = sched

        task = cur.execute("SELECT * FROM blinds_task WHERE schedule_id = ?",
                           (sched_id, )).fetchall()
        if not task:
            offset = datetime.timedelta(minutes=time_offset)