コード例 #1
0
ファイル: functions.py プロジェクト: SEC-i/ecoControl
def get_operating_costs(device, start):
    workload = Sensor.objects.get(device=device, key='workload')
    max_gas_input = get_device_configuration(device, 'max_gas_input')
    total_gas_consumption = 0
    for value in SensorValueDaily.objects.filter(sensor=workload, timestamp__gte=start):
        step = (value.value / 100.0) * (120 / 3600.0)
        total_gas_consumption += max_gas_input * step
    return '%s Euro' % round(total_gas_consumption * get_configuration('gas_costs'), 2)
コード例 #2
0
def get_operating_costs(device, start):
    workload = Sensor.objects.get(device=device, key='workload')
    max_gas_input = get_device_configuration(device, 'max_gas_input')
    total_gas_consumption = 0
    for value in SensorValueDaily.objects.filter(sensor=workload,
                                                 timestamp__gte=start):
        step = (value.value / 100.0) * (120 / 3600.0)
        total_gas_consumption += max_gas_input * step
    return '%s Euro' % round(
        total_gas_consumption * get_configuration('gas_costs'), 2)
コード例 #3
0
def get_statistics_for_cogeneration_unit(start=None, end=None):
    output = []

    try:
        for device in Device.objects.filter(device_type=Device.CU):
            device_output = []
            device_output.append(('type', Device.CU))
            device_output.append(('device_id', device.id))
            device_output.append(('device_name', device.name))

            sensor_workload = Sensor.objects.get(device=device, key='workload')
            sensor_consumption = Sensor.objects.get(
                device=device, key='current_gas_consumption')
            workloads = SensorValueDaily.objects.filter(sensor=sensor_workload)
            workloads_monthly_avg = SensorValueMonthlyAvg.objects.filter(
                sensor=sensor_workload)
            consumptions_monthly_sum = SensorValueMonthlySum.objects.filter(
                sensor=sensor_consumption)
            if start is not None:
                workloads = workloads.filter(timestamp__gte=start)
                workloads_monthly_avg = workloads_monthly_avg.filter(
                    timestamp__gte=start)
                consumptions_monthly_sum = consumptions_monthly_sum.filter(
                    timestamp__gte=start)
            if end is not None:
                workloads = workloads.filter(timestamp__lte=end)
                workloads_monthly_avg = workloads_monthly_avg.filter(
                    timestamp__lte=end)
                consumptions_monthly_sum = consumptions_monthly_sum.filter(
                    timestamp__lte=end)

            hours_of_operation = workloads.filter(value__gt=0).count() * 24

            device_output.append(
                ('hours_of_operation', round(hours_of_operation, 2)))

            device_output.append(
                ('average_workload',
                 round(workloads_monthly_avg.latest('timestamp').avg, 2)))

            thermal_efficiency = get_device_configuration(
                device, 'thermal_efficiency')
            electrical_efficiency = get_device_configuration(
                device, 'electrical_efficiency')
            max_gas_input = get_device_configuration(device, 'max_gas_input')

            total_gas_consumption = consumptions_monthly_sum.latest(
                'timestamp').sum
            total_electrical_production = total_gas_consumption * \
                electrical_efficiency
            total_thermal_production = total_gas_consumption * \
                thermal_efficiency
            device_output.append(
                ('total_thermal_production', round(total_thermal_production,
                                                   2)))
            device_output.append(('total_electrical_production',
                                  round(total_electrical_production, 2)))
            device_output.append(
                ('total_gas_consumption', round(total_gas_consumption, 2)))

            gas_costs = get_configuration('gas_costs')
            operating_costs = total_gas_consumption * gas_costs
            device_output.append(('operating_costs', round(operating_costs,
                                                           2)))

            values = list(workloads)
            device_output.append(('values_count', len(values)))

            power_ons = 0
            last_time_on = None
            for value in values:
                if last_time_on is None:
                    last_time_on = value.value > 0

                if (last_time_on
                        and value.value == 0) or (not last_time_on
                                                  and value.value > 0):
                    power_ons += 1
                    last_time_on = not last_time_on

            device_output.append(('power_ons', power_ons))

            output.append(dict(device_output))

    except (Device.DoesNotExist, DeviceConfiguration.DoesNotExist,
            Configuration.DoesNotExist, Sensor.DoesNotExist,
            SensorValue.DoesNotExist, SensorValueMonthlyAvg.DoesNotExist) as e:
        logger.warning("DoesNotExist error: %s" % e)

    return output
コード例 #4
0
def get_live_data():
    output = {
        'electrical_consumption': '',
        'cu_workload': '',
        'cu_thermal_production': '',
        'cu_electrical_production': '',
        'cu_operating_costs': '',
        'hs_temperature': '',
        'infeed_costs': '',
        'infeed_reward': '',
        'plb_workload': '',
        'plb_thermal_production': '',
        'plb_operating_costs': '',
        'thermal_consumption': '',
        'warmwater_consumption': '',
        'time': ''
    }

    try:
        output['time'] = SensorValue.objects.all().latest(
            'timestamp').timestamp
        last_month = get_past_time(months=1)

        for device in Device.objects.all():
            if device.device_type == Device.HS:
                output['hs_temperature'] = get_latest_value_with_unit(
                    device, 'get_temperature')
            elif device.device_type == Device.PM:
                output['infeed_costs'] = get_latest_value_with_unit(
                    device, 'purchased')
                output['infeed_reward'] = get_latest_value_with_unit(
                    device, 'fed_in_electricity')
            elif device.device_type == Device.CU:
                output['cu_workload'] = get_latest_value_with_unit(
                    device, 'workload')
                workload = get_latest_value(device, 'workload')
                thermal_production = round(
                    workload *
                    get_device_configuration(device, 'thermal_efficiency') /
                    100.0, 2)
                output['cu_thermal_production'] = '%s kWh' % thermal_production
                electrical_efficiency = round(
                    workload *
                    get_device_configuration(device, 'electrical_efficiency') /
                    100.0, 2)
                output[
                    'cu_electrical_production'] = '%s kWh' % electrical_efficiency
                output['cu_operating_costs'] = get_operating_costs(
                    device, last_month)
            elif device.device_type == Device.PLB:
                output['plb_workload'] = get_latest_value_with_unit(
                    device, 'workload')
                thermal_production = round(
                    get_latest_value(device, 'workload') *
                    get_device_configuration(device, 'thermal_efficiency') /
                    100.0, 2)
                output[
                    'plb_thermal_production'] = '%s kWh' % thermal_production
                output['plb_operating_costs'] = get_operating_costs(
                    device, last_month)
            elif device.device_type == Device.TC:
                output['thermal_consumption'] = get_latest_value_with_unit(
                    device, 'get_consumption_power')
                output['warmwater_consumption'] = get_latest_value_with_unit(
                    device, 'get_warmwater_consumption_power')
            elif device.device_type == Device.EC:
                output['electrical_consumption'] = get_latest_value_with_unit(
                    device, 'get_consumption_power')
    except SensorValue.DoesNotExist:
        logger.debug('SensorValue.DoesNotExist')

    return output
コード例 #5
0
ファイル: functions.py プロジェクト: SEC-i/ecoControl
def get_statistics_for_cogeneration_unit(start=None, end=None):
    output = []

    try:
        for device in Device.objects.filter(device_type=Device.CU):
            device_output = []
            device_output.append(('type', Device.CU))
            device_output.append(('device_id', device.id))
            device_output.append(('device_name', device.name))

            sensor_workload = Sensor.objects.get(device=device, key='workload')
            sensor_consumption = Sensor.objects.get(
                device=device, key='current_gas_consumption')
            workloads = SensorValueDaily.objects.filter(sensor=sensor_workload)
            workloads_monthly_avg = SensorValueMonthlyAvg.objects.filter(
                sensor=sensor_workload)
            consumptions_monthly_sum = SensorValueMonthlySum.objects.filter(
                sensor=sensor_consumption)
            if start is not None:
                workloads = workloads.filter(timestamp__gte=start)
                workloads_monthly_avg = workloads_monthly_avg.filter(
                    timestamp__gte=start)
                consumptions_monthly_sum = consumptions_monthly_sum.filter(
                    timestamp__gte=start)
            if end is not None:
                workloads = workloads.filter(timestamp__lte=end)
                workloads_monthly_avg = workloads_monthly_avg.filter(
                    timestamp__lte=end)
                consumptions_monthly_sum = consumptions_monthly_sum.filter(
                    timestamp__lte=end)

            hours_of_operation = workloads.filter(
                value__gt=0).count() * 24

            device_output.append(
                ('hours_of_operation', round(hours_of_operation, 2)))

            device_output.append(
                ('average_workload', round(workloads_monthly_avg.latest('timestamp').avg, 2)))

            thermal_efficiency = get_device_configuration(
                device, 'thermal_efficiency')
            electrical_efficiency = get_device_configuration(
                device, 'electrical_efficiency')
            max_gas_input = get_device_configuration(device, 'max_gas_input')

            total_gas_consumption = consumptions_monthly_sum.latest('timestamp').sum
            total_electrical_production = total_gas_consumption * \
                electrical_efficiency
            total_thermal_production = total_gas_consumption * \
                thermal_efficiency
            device_output.append(
                ('total_thermal_production', round(total_thermal_production, 2)))
            device_output.append(
                ('total_electrical_production', round(total_electrical_production, 2)))
            device_output.append(
                ('total_gas_consumption', round(total_gas_consumption, 2)))

            gas_costs = get_configuration('gas_costs')
            operating_costs = total_gas_consumption * gas_costs
            device_output.append(
                ('operating_costs', round(operating_costs, 2)))

            values = list(workloads)
            device_output.append(('values_count', len(values)))

            power_ons = 0
            last_time_on = None
            for value in values:
                if last_time_on is None:
                    last_time_on = value.value > 0

                if (last_time_on and value.value == 0) or (not last_time_on and value.value > 0):
                    power_ons += 1
                    last_time_on = not last_time_on

            device_output.append(('power_ons', power_ons))

            output.append(dict(device_output))

    except (Device.DoesNotExist, DeviceConfiguration.DoesNotExist, Configuration.DoesNotExist, Sensor.DoesNotExist, SensorValue.DoesNotExist, SensorValueMonthlyAvg.DoesNotExist) as e:
        logger.warning("DoesNotExist error: %s" % e)

    return output
コード例 #6
0
ファイル: functions.py プロジェクト: SEC-i/ecoControl
def get_live_data():
    output = {
        'electrical_consumption': '',
        'cu_workload': '',
        'cu_thermal_production': '',
        'cu_electrical_production': '',
        'cu_operating_costs': '',
        'hs_temperature': '',
        'infeed_costs': '',
        'infeed_reward': '',
        'plb_workload': '',
        'plb_thermal_production': '',
        'plb_operating_costs': '',
        'thermal_consumption': '',
        'warmwater_consumption': '',
        'time': ''
    }

    try:
        output['time'] = SensorValue.objects.all().latest(
            'timestamp').timestamp
        last_month = get_past_time(months=1)

        for device in Device.objects.all():
            if device.device_type == Device.HS:
                output['hs_temperature'] = get_latest_value_with_unit(
                    device, 'get_temperature')
            elif device.device_type == Device.PM:
                output['infeed_costs'] = get_latest_value_with_unit(
                    device, 'purchased')
                output['infeed_reward'] = get_latest_value_with_unit(
                    device, 'fed_in_electricity')
            elif device.device_type == Device.CU:
                output['cu_workload'] = get_latest_value_with_unit(
                    device, 'workload')
                workload = get_latest_value(device, 'workload')
                thermal_production = round(
                    workload * get_device_configuration(device, 'thermal_efficiency') / 100.0, 2)
                output['cu_thermal_production'] = '%s kWh' % thermal_production
                electrical_efficiency = round(
                    workload * get_device_configuration(device, 'electrical_efficiency') / 100.0, 2)
                output[
                    'cu_electrical_production'] = '%s kWh' % electrical_efficiency
                output['cu_operating_costs'] = get_operating_costs(
                    device, last_month)
            elif device.device_type == Device.PLB:
                output['plb_workload'] = get_latest_value_with_unit(
                    device, 'workload')
                thermal_production = round(
                    get_latest_value(device, 'workload') * get_device_configuration(device, 'thermal_efficiency') / 100.0, 2)
                output[
                    'plb_thermal_production'] = '%s kWh' % thermal_production
                output['plb_operating_costs'] = get_operating_costs(
                    device, last_month)
            elif device.device_type == Device.TC:
                output['thermal_consumption'] = get_latest_value_with_unit(
                    device, 'get_consumption_power')
                output['warmwater_consumption'] = get_latest_value_with_unit(
                    device, 'get_warmwater_consumption_power')
            elif device.device_type == Device.EC:
                output['electrical_consumption'] = get_latest_value_with_unit(
                    device, 'get_consumption_power')
    except SensorValue.DoesNotExist:
        logger.debug('SensorValue.DoesNotExist')

    return output