SimpleMetric doesn't show any data

Hi All,

I’m probably doing something wrong but I’m not able to find the error. My simple metric assume always value 0 (missing).

Here some useful info:

entity type ChInRevproTdApparatus mixes External, NoSystemCols , MetricEvaluatable schema name 'apparatus' {
    id:                                    ~ schema name 'apparatusid'
    servicePointId:                        string schema name 'servicepointid'
    companyId:                             int schema name 'companyid'
    apparatusType:                         string schema name 'apparatustype'
    apparatusNumber:                       long int schema name 'apparatusnumber'
    modelCode:                             string schema name 'modelcode'
    equipmentBrand:                        string schema name 'equipmentbrand'
    equipmentOwnership:                    string schema name 'equipmentownership'
    apparatusStatus:                       string schema name 'apparatusstatus'
    firstInstallationDateTime:             datetime schema name 'firstinstallationdatetime'
    lastInstallationDateTime:              datetime schema name 'lastinstallationdatetime'
    retirementDateTime:                    datetime schema name 'retirementdatetime'
    manufacturingYear:                     int schema name 'manufacturingyear'
    measurementType:                       string schema name 'measurementtype'
    measurementTypeName:                   string schema name 'measurementtypename'
    constantValue:                         long int schema name 'constantValue'
    modelName:                             string schema name 'modelname'
    phase:                                 string schema name 'phase'
    amperage:                              string schema name 'amperage'
    voltage:                               string schema name 'voltage'

    inspectionStatisticsGroupByMeterBrand: [ChInRevproTdInspectionStatisticsGroupByMeterBrand](meterBrand, equipmentBrand)
}

entity type ChInRevproTdInspectionStatisticsGroupByMeterBrand mixes External, NoSystemCols schema name 'inspectionstatisticsgroupbymeterbrand' {
    id:                            ~ schema name 'statisticsid'
    companyId:                     int schema name 'companyid'
    meterBrand:                    string schema name 'meterbrand'
    statisticsDateTime:            datetime schema name 'statisticsdatetime'
    inspectionCount:               int schema name 'inspectioncount'
    fraudCount:                    int schema name 'fraudcount'
    unregisteredConsumptionCount:  int schema name 'unregisteredconsumptioncount'
    normalCount:                   int schema name 'normalcount'
    retiredCount:                  int schema name 'retiredcount'
    totalCalculatedValueKwh:       double schema name 'totalcalculatedvaluekwh'
    falsePositiveCount:            int schema name 'falsepositivecount'
    truePositiveCount:             int schema name 'truepositivecount'
    truePositiveWithEnergyCount:   int schema name 'truepositivewithenergycount'
    truePositiveWithNoEnergyCount: int schema name 'truepositivewithnoenergycount'
}

My SimpleMetric

{
    "srcType": "ChInRevproTdApparatus",
    "id": "ChInRevproMeMeterBrandInspectionCount_ChInRevproTdApparatus",
    "name": "ChInRevproMeMeterBrandInspectionCount",
    "tsDecl": {
        "data": "inspectionStatisticsGroupByMeterBrand",
        "treatment": "SUM",
        "start": "statisticsDateTime",
        "value": "inspectionCount",
        "filter": "companyId == 1"
    },
    "description": "Number of inspections on meters of the specified brand."
}

With this command I see data between 2008-2017:
c3Grid(ChInRevproTdInspectionStatisticsGroupByMeterBrand.fetch({filter: “meterBrand == ‘ABB’”}))

In particular inspectionCount is > 0 for different dates in this range.

Also this command show that ABB is in the related table:
c3Grid(ChInRevproTdApparatus.fetch({filter: “equipmentBrand == ‘ABB’”}))

But if I run

emr = ChInRevproTdApparatus.evalMetrics({
    "ids" : [ "ABB" ],
    "expressions" : ['ChInRevproMeMeterBrandInspectionCount'],
    "interval" : "DAY",
    "start" : "2008-01-01T00:00:00",
    "end" : "2017-08-01T00:00:00",
})

I obtain a series of zeros.

Best,
Mario

@mnslarcher I see you apply a filter in the metric - if you fetch the data with same filter does it return records? In the tsDecl can you try to assign endDate the value of statisticsDateTime and start with like a second less

end - period(1,’SECOND’)

Hi Marco, yes, if I run:

c3Grid(ChInRevproTdInspectionStatisticsGroupByMeterBrand.fetch({filter: “(meterBrand == ‘ABB’) && (companyId == 1)”}))

I obtain the same result, because basically all my records have companyId == 1.

I tried also your suggestion:

var sm = SimpleMetric.make({
“srcType”: “ChInRevproTdApparatus”,
“id”: “ChInRevproMeMeterBrandInspectionCount_ChInRevproTdApparatus”,
“name”: “ChInRevproMeMeterBrandInspectionCount”,
“tsDecl”: {
“data”: “inspectionStatisticsGroupByMeterBrand”,
“treatment”: “SUM”,
“start”: “statisticsDateTime - period(1,‘SECOND’)”,
“end”: “statisticsDateTime”
“value”: “inspectionCount”,
“filter”: “companyId == 1”
},
“description”: “Number of inspections on meters of the specified brand.”
})

But it didn’t work.

Before moving to 7.9 and changing a table from meter to apparatus (that has
some record more) I had this metric that was working as expected:

{
“srcType”: “ChInRevproTdMeter”,
“id”: “ChInRevproMeMeterBrandInspectionCount_ChInRevproTdMeter”,
“name”: “ChInRevproMeMeterBrandInspectionCount”,
“tsDecl”: {
“data”: “inspectionStatisticsGroupByMeterBrand”,
“treatment”: “SUM”,
“start”: “statisticsDateTime”,
“value”: “inspectionCount”,
“filter”: “companyId == 1”
},
“description”: “Number of inspections on meters of the specified brand.”
}

Also for reference before the types were (for me basically nothing changed but still now it doesn’t work anymore):

entity type ChInRevproTdMeter mixes External, NoSystemCols , MetricEvaluatable schema name 'meter' {
    id:                                    ~ schema name 'meterid'
    servicePointId:                        string schema name 'servicepointid'
    companyId:                             int schema name 'companyid'
    serialNumber:                          long int schema name 'serialnumber'
    modelCode:                             string schema name 'modelcode'
    brand:                                 string schema name 'brand'
    ownership:                             string schema name 'ownership'
    meterStatus:                           string schema name 'meterstatus'
    firstInstallationDateTime:             datetime schema name 'firstinstallationdatetime'
    lastInstallationDateTime:              datetime schema name 'lastinstallationdatetime'
    retirementDateTime:                    datetime schema name 'retirementdatetime'
    manufacturingYear:                     int schema name 'manufacturingyear'
    measurementType:                       string schema name 'measurementtype'
    measurementTypeName:                   string schema name 'measurementtypename'
    constant:                              long int schema name 'constant'
    modelName:                             string schema name 'modelname'
    phase:                                 string schema name 'phase'
    amperage:                              string schema name 'amperage'
    voltage:                               string schema name 'voltage'

    inspectionStatisticsGroupByMeterBrand: [ChInRevproTdInspectionStatisticsGroupByMeterBrand](meterBrand, brand)
}

entity type ChInRevproTdInspectionStatisticsGroupByMeterBrand mixes External, NoSystemCols schema name 'inspectionstatisticsgroupbymeterbrand' {
    id:                            ~ schema name 'statisticsid'
    companyId:                     int schema name 'companyid'
    meterBrand:                    string schema name 'meterbrand'
    statisticsDateTime:            datetime schema name 'statisticsdatetime'
    inspectionCount:               int schema name 'inspectioncount'
    fraudCount:                    int schema name 'fraudcount'
    unregisteredConsumptionCount:  int schema name 'unregisteredconsumptioncount'
    normalCount:                   int schema name 'normalcount'
    retiredCount:                  int schema name 'retiredcount'
    totalCalculatedValueKwh:       double schema name 'totalcalculatedvaluekwh'
    falsePositiveCount:            int schema name 'falsepositivecount'
    truePositiveCount:             int schema name 'truepositivecount'
    truePositiveWithEnergyCount:   int schema name 'truepositivewithenergycount'
    truePositiveWithNoEnergyCount: int schema name 'truepositivewithnoenergycount'
}

Hi all,

The problem now is fixed (thanks to Gabriel), the point was that I was evaluating the metric on a meterBrand (‘ABB’) instead of on a id of the table ChInRevproTdApparatus.

The two table are connected using meterBrand <–> equipmentBrand but still the correct thing to do is to call the metric using the type id, not the one used to connect the two tables.

Best,
Mario