Coursera Training

#1

For some reason when I provision my code for Coursera training of part 4-6. The SimpleMetric and CompoundMetric types I defined were not loaded. And I got a warning like this:

main.js:917 Expected metric AverageTemperature not found for source type SmartBulb 
{fileUrl: "meta:///lightbulbTraining/src/types/SmartBulb.c3typ", lineNum: 5, colNum: 1, severity: "WARNING", targetType: "SmartBulb"}
colNum: 1
fileUrl: "meta:///lightbulbTraining/src/types/SmartBulb.c3typ"
lineNum: 5
severity: "WARNING"
targetType: "SmartBulb"
__proto__: Object

Does anyone know what are the potential problems?

#2

Can you please confirm you have in your package “seed/SimpleMetric/AverageTemperature_SmartBulb.json” and that is defined as:

{
“id”: “AverageTemperature_SmartBulb”,
“name”: “AverageTemperature”,
“description”: “Average temperature over time of the SmartBulb”,
“path”: “bulbMeasurements”,
“expression”: “avg(avg(normalized.data.temperature))”,
“srcType”: “SmartBulb”
}

#3

Yes. I do have this metric defined in the directory.

#4

Can you post your SmartBulb.c3typ file?

#5
/**
* SmartBulb.c3typ
* A bulb capable of storing power consumption, light output, location, and more.
*/
entity type SmartBulb extends LightBulb mixes MetricEvaluatable type key "SMRT_BLB"
{
 // The latitude of this bulb.
 latitude: double
 // The longitude of this bulb.
 longitude: double
 // The unit of measurement used for this bulb's light output measurements.
 lumensUOM: Unit
 // The unit of measurement used for this bulb's power consumption measurements.
 powerUOM: Unit
 // The unit of measurement used for this bulb's temperature measurements.
 temperatureUOM: Unit
 // The unit of measurement used for this bulb's voltage measurements.
voltageUOM: Unit
 // This bulb's historical events.
 bulbEvents: [SmartBulbEvent](smartBulb)
// This bulb's historical measurements.
 bulbMeasurements: [SmartBulbMeasurementSeries](smartBulb)
// The collection of relations that pertain to this smart bulb.
@db(order='descending(start), descending(end)')
fixtureHistory: [SmartBulbToFixtureRelation](from)
// The current {@link Fixture} to which this smart bulb is attached.
currentFixture: Fixture stored calc 'fixtureHistory[0].(end == null).to'
/**
* Returns the life span of this smartBulb
 */
 lifeSpanInYears: function(bulbId: string): double js server

 /**
* Returns the longest life span of any smartBulb
 */
 longestLifeSpanBulb: function(): string js server

 /**
* Returns the shortest life span of any smartBulb
 */
 shortestLifeSpanBulb: function(): string js server

 /**
* Returns the avg life span of all smartBulbs
 */
 averageLifeSpan: function(): double js server

 /**
  * This bulb's historical predictions.
  */
 @db(order='descending(timestamp)')
 bulbPredictions: [SmartBulbPrediction](smartBulb)

 /**
  * This bulb's latest prediction.
  */
 currentPrediction:  SmartBulbPrediction stored calc "bulbPredictions[0]"


}
#6

This file seems ok. I would suggest doing the following:

  • double checking your provisioning the correct “package” name

  • make sure the spellings are correct in all files - It happened to me to misspell a word and took some time to figure what was wrong

If you are at Part 4 your folder/files structure should be like this

  • repository.json

  • lightbulbTraining:
    package.json

    • seed:

      • CompoundMetric:
        DurationOnInHours.json
        HasEverFailed.json
        IsDefective.json
        SwitchCount.json
        SwitchCountPreviousWeek.json
        WillFailNextMonth.json

      • FileSourceCollection:
        CanonicalFixture.json
        CanonicalPowerGridStatus.json
        CanonicalSmartBulb.json
        CanonicalSmartBulbEvent.json
        CanonicalSmartBulbMeasurement.json
        CanonicalSmartBulbToFixtureRelation.json

      • SimpleMetric:
        AverageLumens_SmartBulb.json
        AveragePower_SmartBulb.json
        AverageTemperature_SmartBulb.json
        AverageVoltage_SmartBulb.json
        PowerGridStatus_Building.json
        PowerGridStatus_SmartBulb.json
        Status_SmartBulb.json

    • src:

      • canonicals:
        CanonicalFixture.c3typ
        CanonicalPowerGridStatus.c3typ
        CanonicalSmartBulb.c3typ
        CanonicalSmartBulbEvent.c3typ
        CanonicalSmartBulbMeasurement.c3typ
        CanonicalSmartBulbToFixtureRelation.c3typ

      • transforms:
        TransformCanonicalFixtureToApartment.c3typ
        TransformCanonicalFixtureToBuilding.c3typ
        TransformCanonicalFixtureToFixture.c3typ
        TransformCanonicalPowerGridStatusToBuilding.c3typ
        TransformCanonicalSmartBulbEventToSmartBulbEvent.c3typ
        TransformCanonicalSmartBulbMeasurementToSmartBulbMeasurement.c3typ
        TransformCanonicalSmartBulbMeasurementToSmartBulbMeasurementSeries.c3typ
        TransformCanonicalSmartBulbToFixtureRelationToSmartBulbToFixtureRelation.c3typ
        TransformCanonicalSmartBulbToManufacturer.c3typ
        TransformCanonicalSmartBulbToSmartBulb.c3typ

      • types:
        Apartment.c3typ
        Building.c3typ
        Fixture.c3typ
        LightBulb.c3typ
        Manufacturer.c3typ
        PowerGridStatus.c3typ
        PowerGridStatusSet.c3typ
        SmartBulb.c3typ
        SmartBulb.js
        SmartBulbEvent.c3typ
        SmartBulbMeasurement.c3typ
        SmartBulbMeasurementSeries.c3typ
        SmartBulbToFixtureRelation.c3typ

#7

Thanks! I will double check the spelling in the code and the file structure.

#8

Was this resolved? I’m having a similar problem with Part 4, where no metrics are being loaded to SmartBulb.
Calling SmartBulb.listMetrics() only gives the 10 it inherits (DayOfWeek, etc).
I’ve tried loading the pre-made files from the next training lesson and I’m having the same issue.

#9

Not sure. I was given a 7.8 environment to work on this week so I did not follow-up on this one.