예제 #1
0
파일: meters.py 프로젝트: riahtu/seed
    def _build_column_def(self, meter, column_defs):
        type_text = meter.get_type_display()
        if meter.source == meter.GREENBUTTON:
            source = 'GB'
            source_id = usage_point_id(meter.source_id)
        elif meter.source == meter.BUILDINGSYNC:
            source = 'BS'
            source_id = meter.source_id
        else:
            source = 'PM'
            source_id = meter.source_id

        field_name = '{} - {} - {}'.format(type_text, source, source_id)

        if meter.type == Meter.COST:
            display_unit = "{} Dollars".format(self._org_country)
            conversion_factor = 1
        else:
            display_unit = self.org_meter_display_settings[type_text]
            conversion_factor = self.factors[type_text][display_unit]

        column_defs[field_name] = {
            'field': field_name,
            'displayName': '{} ({})'.format(field_name, display_unit),
            '_filter_type': 'reading',
        }

        return field_name, conversion_factor
예제 #2
0
    def proposed_imports(self):
        """
        Summarizes meters and readings that will be created via file import.

        If this is a GreenButton import, take the UsagePoint as the source_id.
        """
        summaries = []
        energy_type_lookup = dict(Meter.ENERGY_TYPES)
        property_ids_to_pm_ids = {
            v: k
            for k, v in self._source_to_property_ids.items()
        }

        for meter in self.meter_and_reading_objs:
            meter_summary = {
                'type': energy_type_lookup[meter['type']],
                'incoming': len(meter.get("readings")),
            }

            id = meter.get("source_id")
            if meter['source'] == Meter.PORTFOLIO_MANAGER:
                meter_summary['source_id'] = id
                meter_summary['pm_property_id'] = property_ids_to_pm_ids[
                    meter.get("property_id")]
            else:
                meter_summary['source_id'] = usage_point_id(id)

            summaries.append(meter_summary)

        return summaries
예제 #3
0
    def property_meters(self, request):
        body = dict(request.data)
        property_view_id = body['property_view_id']

        property_id = PropertyView.objects.get(pk=property_view_id).property.id
        energy_types = dict(Meter.ENERGY_TYPES)

        res = []
        for meter in Meter.objects.filter(property_id=property_id):
            if meter.source == meter.GREENBUTTON:
                source = 'GB'
                source_id = usage_point_id(meter.source_id)
            elif meter.source == meter.BUILDINGSYNC:
                source = 'BS'
                source_id = meter.source_id
            else:
                source = 'PM'
                source_id = meter.source_id

            res.append({
                'id':
                meter.id,
                'type':
                energy_types[meter.type],
                'source':
                source,
                'source_id':
                source_id,
                'scenario_id':
                meter.scenario.id if meter.scenario is not None else None,
                'scenario_name':
                meter.scenario.name if meter.scenario is not None else None
            })

        return res
예제 #4
0
    def proposed_imports(self):
        """
        Summarizes meters and readings that will be created via file import.

        If this is a GreenButton import, take the UsagePoint as the source_id.
        """
        if self._cache_meter_and_reading_objs is None:
            # Making sure to build out meters and meter readings first
            self.meter_and_reading_objs

        if self._cache_proposed_imports is None:
            self._cache_proposed_imports = []
            energy_type_lookup = dict(Meter.ENERGY_TYPES)

            # Gather info based on property_id - cycles (query) and related pm_property_ids (parsed in different method)
            property_ids_info = {}
            for pm_property_id, property_ids in self._source_to_property_ids.items():
                for property_id in property_ids:
                    property_ids_info[property_id] = {'pm_id': pm_property_id}

                    cycle_names = list(
                        PropertyView.objects.select_related('cycle').
                        order_by('cycle__end').
                        filter(property_id=property_id).
                        values_list('cycle__name', flat=True)
                    )
                    property_ids_info[property_id]['cycles'] = ', '.join(cycle_names)

            # Put summaries together based on source type
            for meter in self.meter_and_reading_objs:
                meter_summary = {
                    'type': energy_type_lookup[meter['type']],
                    'incoming': len(meter.get("readings")),
                    'property_id': meter['property_id'],
                }

                id = meter.get("source_id")
                if meter['source'] == Meter.PORTFOLIO_MANAGER:
                    property_id_info = property_ids_info[meter.get("property_id")]

                    meter_summary['source_id'] = id
                    meter_summary['pm_property_id'] = property_id_info['pm_id']
                    meter_summary['cycles'] = property_id_info['cycles']
                else:
                    meter_summary['source_id'] = usage_point_id(id)

                self._cache_proposed_imports.append(meter_summary)

        return self._cache_proposed_imports
예제 #5
0
파일: meters.py 프로젝트: zolton1/seed
    def property_meters(self, request):
        body = dict(request.data)
        property_view_id = body['property_view_id']

        property_id = PropertyView.objects.get(pk=property_view_id).property.id
        energy_types = dict(Meter.ENERGY_TYPES)

        return [{
            'id':
            meter.id,
            'type':
            energy_types[meter.type],
            'source':
            "PM" if meter.source == Meter.PORTFOLIO_MANAGER else "GB",
            'source_id':
            meter.source_id if meter.source == Meter.PORTFOLIO_MANAGER else
            usage_point_id(meter.source_id),
        } for meter in Meter.objects.filter(property_id=property_id)]
예제 #6
0
파일: meters.py 프로젝트: zolton1/seed
    def _build_column_def(self, meter, column_defs):
        type_text = meter.get_type_display()
        source = 'PM' if meter.source == meter.PORTFOLIO_MANAGER else 'GB'
        source_id = meter.source_id if source == 'PM' else usage_point_id(
            meter.source_id)
        field_name = '{} - {} - {}'.format(type_text, source, source_id)

        if meter.type == Meter.COST:
            display_unit = "{} Dollars".format(self._org_country)
            conversion_factor = 1
        else:
            display_unit = self.org_meter_display_settings[type_text]
            conversion_factor = self.factors[type_text][display_unit]

        column_defs[field_name] = {
            'field': field_name,
            'displayName': '{} ({})'.format(field_name, display_unit),
            '_filter_type': 'reading',
        }

        return field_name, conversion_factor