Example #1
0
    def on_OadrRegisterReport_send(self, venID):
        db_reports = MetadataReports.find({MetadataReports.owned(): True})
        requestID = "0"
        reportRequestID = 0
        reports = [{
            "duration":
            db_r.duration,
            "eiReportID":
            db_r.eiReportID,
            "data_points": [{
                "rID": dp.rID,
                "oadrMinPeriod": dp.oadrMinPeriod,
                "oadrMaxPeriod": dp.oadrMaxPeriod,
                "oadrOnChange": dp.oadrOnChange,
                "marketContext": dp.marketContext,
                "reportType": dp.reportType,
                "readingType": dp.readingType
            } for dp in DataPoint.find({DataPoint.report(): db_r._id})],
            "reportRequestID":
            "0",
            "reportSpecifierID":
            db_r.specifierID,
            "reportName":
            db_r.reportName,
            "createdDateTime":
            db_r.createdDateTime.strftime("%Y-%m-%dT%H:%M:%S")
        } for db_r in db_reports]

        return requestID, reportRequestID, reports
Example #2
0
    def auto_subscription_reports_create(self, venID):
        """ When called sends oadrCreateReport with all the reports recieved by the VEN
        """
        # get all reports from user:
        ven = VEN.find_one({VEN.ven_id(): venID})
        reports = MetadataReports.find({MetadataReports.ven(): ven._id})
        report_data_points = {}
        for report in reports:
            report_data_points[report] = {
                "data_points": DataPoint.find({DataPoint.report():
                                               report._id}),
                "devices": Device.find({Device.report(): report._id})
            }

        register_reports = []
        for report, data_points in report_data_points.items():
            register_data_points = []
            for data_point in data_points['data_points']:
                for k, v in data_point.reporting_items.items():
                    register_data_points.append(
                        (data_point, v['oadr_name'], v['reading_type']))
                    data_point.reporting_items[k]['subscribed'] = True
                    data_point.save()

            for device in data_points['devices']:
                for k, v in device.status.items():
                    register_data_points.append(
                        (device, v['oadr_name'], v['reading_type']))
                    device.status[k]['subscribed'] = True
                    device.save()

            report.subscribed = True
            report.save()
            register_reports.append((report, register_data_points))

        if register_reports:
            createReport = OadrCreateReport()
            report_types = [{
                "reportId":
                x.ei_report_id,
                "specifierId":
                x.specifier_id,
                "data_points": [{
                    'rid':
                    "{}_{}".format(
                        map_rid_device_id.find_one({
                            map_rid_device_id.device_id():
                            d[0].device_id
                        }).rid, d[1]),
                    'reading_type':
                    d[2]
                } for d in y]
            } for x, y in register_reports]
            params = {"requestID": "0", "report_types": report_types}
            from oadr_core.vtn.server_blueprint import send_message
            response = send_message(createReport, ven, params)
Example #3
0
    def on_OadrCreatedReport_send(self, venID):
        ven = VEN.find_one({VEN.ven_id: venID})
        if ven is None:
            raise InvalidVenException
        pending_reports = []
        for rep in MetadataReports.find({MetadataReports.ven: ven._id}):
            pending_reports.extend([
                r.reportRequestID
                for r in ReportsToSend.find({ReportsToSend.report: rep._id})
            ])

        return "200", "OK", pending_reports
Example #4
0
    def on_OadrCreateReport_recieved(self, venID, reportRequests):
        ven = VEN.get_ven(venID)
        # respond
        if ven is None:
            raise InvalidVenException

        for r_request in reportRequests:
            self.register_report(r_request)

        pending_reports = []
        for rep in MetadataReports.find({MetadataReports.ven: ven._id}):
            pending_reports.extend([
                r.reportRequestID
                for r in ReportsToSend.find({ReportsToSend.report: rep._id})
            ])

        return "200", "OK", pending_reports
Example #5
0
    def on_OadrCancelReport_recieved(self, venID, cancel_reports,
                                     report_to_follow):
        # respond
        ven = VEN.get_ven(venID)
        if ven is None:
            raise InvalidVenException

        for i in range(0, len(cancel_reports)):
            report_request = cancel_reports[i]
            report = ReportsToSend.find_one(
                {ReportsToSend.report_request_id: report_request})
            if report_to_follow[i]:
                report.canceled = True
                report.save()
            else:
                report.delete()
        pending_reports = []
        for rep in MetadataReports.find({MetadataReports.ven: ven._id}):
            pending_reports.extend([
                r.reportRequestID
                for r in ReportsToSend.find({ReportsToSend.report: rep._id})
            ])

        return "200", "OK", pending_reports