Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4, #6 and #19 from Google doc #513

Merged
merged 3 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions udmif/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion udmif/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
"production": "NODE_ENV=production node -r ts-node/register src/app.ts"
},
"lint-staged": {
"src/**/*.{ts,tsx,json}": "prettier --single-quote --arrow-parens always --trailing-comma es5 --print-width 120 --write"
"{src,util}/**/*.{ts,tsx,json}": "prettier --single-quote --arrow-parens always --trailing-comma es5 --print-width 120 --write"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Object {
"firmware": "v-1",
"id": "00000000-0000-0000-0000-000000000001",
"lastPayload": "2022-08-30",
"lastSeen": "2022-07-16T18:27:19Z",
"lastStateSaved": null,
"lastStateUpdated": null,
"lastTelemetrySaved": null,
"lastTelemetryUpdated": null,
"level": 400,
"make": "make-1",
"message": "Tickity Boo",
Expand Down
5 changes: 4 additions & 1 deletion udmif/api/src/__tests__/device/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ const QUERY_DEVICE = gql`
level
message
details
lastSeen
state
errorsCount
lastStateUpdated
lastStateSaved
lastTelemetryUpdated
lastTelemetrySaved
}
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ Object {
"data": Object {
"site": Object {
"correctDevicesCount": 1,
"correctDevicesPercent": 0.25,
"deviceErrors": Array [],
"errorDevicesCount": 1,
"errorDevicesPercent": 0.25,
"extraDevicesCount": 0,
"lastValidated": "2022-07-16T18:27:19Z",
"missingDevicesCount": 2,
"missingDevicesPercent": 0.5,
"name": "LOC-1",
"percentValidated": 0.4,
"seenDevicesCount": 10,
"totalDeviceErrorsCount": 0,
"totalDevicesCount": 10,
"totalDevicesCount": 4,
"validation": "{\\"version\\":\\"1.3.14\\",\\"last_updated\\":\\"2022-07-16T18:27:19Z\\",\\"timestamp\\":\\"2018-08-26T21:39:29.364Z\\",\\"summary\\":{\\"correct_devices\\":[\\"AHU-22\\"],\\"extra_devices\\":[],\\"missing_devices\\":[\\"GAT-123\\",\\"SNS-4\\"],\\"error_devices\\":[\\"AHU-1\\"]},\\"status\\":{\\"message\\":\\"Site is completed validation\\",\\"category\\":\\"validation.summary.report\\",\\"timestamp\\":\\"2018-08-26T21:39:30.364Z\\",\\"level\\":200},\\"devices\\":{\\"AHU-1\\":{\\"last_seen\\":\\"2022-07-16T18:27:19Z\\",\\"oldest_mark\\":\\"2022-07-16T18:27:19Z\\",\\"status\\":{\\"message\\":\\"Tickity Boo\\",\\"category\\":\\"validation.device.result\\",\\"timestamp\\":\\"2018-08-26T21:39:30.364Z\\",\\"level\\":400}}}}",
},
},
Expand Down
5 changes: 4 additions & 1 deletion udmif/api/src/__tests__/site/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ const QUERY_SITE = gql`
query {
site(name: "00000000-0000-0000-0000-0000000001") {
name
seenDevicesCount
totalDevicesCount
correctDevicesCount
correctDevicesPercent
missingDevicesCount
missingDevicesPercent
errorDevicesCount
errorDevicesPercent
extraDevicesCount
lastValidated
percentValidated
deviceErrors {
timestamp
message
Expand Down
4 changes: 4 additions & 0 deletions udmif/api/src/device/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ export interface Device {
tags?: string[];
points?: Point[];
validation?: any;
lastStateUpdated?: string;
lastStateSaved?: string;
lastTelemetryUpdated?: string;
lastTelemetrySaved?: string;
}
3 changes: 0 additions & 3 deletions udmif/api/src/device/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ export const resolvers = {
details: async (device: Device, _args, { dataSources: { siteDS } }: ApolloContext) => {
return (await siteDS.getSite(device.site))?.validation?.devices[device.name]?.status?.details;
},
lastSeen: async (device: Device, _args, { dataSources: { siteDS } }: ApolloContext) => {
return (await siteDS.getSite(device.site))?.validation?.devices[device.name]?.last_seen;
},
state: async (device: Device, _args, { dataSources: { siteDS } }: ApolloContext) => {
const siteValidationSummary = (await siteDS.getSite(device.site))?.validation?.summary;

Expand Down
10 changes: 8 additions & 2 deletions udmif/api/src/device/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ type Device {
message: String
# message details from site validation message
details: String
# date last seen from site validation message
lastSeen: String
# timestamp on a telemetry message
lastTelemetryUpdated: String
# timestamp on a device message
lastStateUpdated: String
# timestamp when telemetry was saved to db
lastTelemetrySaved: String
# timestamp when device was saved to db
lastStateSaved: String
# the bin the device fell into during the site validation, i.e. correct, error, missing, or extra
state: DEVICE_STATE
# number of errors from device validation message
Expand Down
22 changes: 21 additions & 1 deletion udmif/api/src/site/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,25 @@ export interface SiteArgs {

export interface Site {
name: string;
validation?: any;
validation?: SiteValidation;
}

export type SiteValidation = {
timestamp?: string;
version?: string;
last_updated: string;
status?: {
message: string;
detail?: string;
category: string;
timestamp: string;
level: number;
};
summary: {
correct_devices?: string[];
extra_devices?: string[];
missing_devices?: string[];
error_devices?: string[];
};
devices: any; //TODO::
};
35 changes: 17 additions & 18 deletions udmif/api/src/site/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sum } from 'lodash';
import { getCorrectDevicesCount, getErrorDevicesCount, getMissingDevicesCount, getTotalDevicesCount } from './siteUtil';
import { DistinctArgs } from '../common/model';
import { ApolloContext } from '../server/datasources';
import { Site, SiteArgs, SitesArgs } from './model';
Expand All @@ -16,37 +16,36 @@ export const resolvers = {
},
},
Site: {
totalDevicesCount: async (site: Site, _args, { dataSources: { deviceDS } }: ApolloContext) => {
seenDevicesCount: async (site: Site, _args, { dataSources: { deviceDS } }: ApolloContext) => {
return (await deviceDS.getDevicesBySite(site.name)).totalFilteredCount;
},
totalDevicesCount: async (site: Site) => {
return getTotalDevicesCount(site);
},
correctDevicesCount: (site: Site) => {
return site.validation?.summary.correct_devices?.length ?? 0;
return getCorrectDevicesCount(site);
},
correctDevicesPercent: (site: Site) => {
return getCorrectDevicesCount(site) / (getTotalDevicesCount(site) || 1);
},
missingDevicesCount: (site: Site) => {
return site.validation?.summary.missing_devices?.length ?? 0;
return getMissingDevicesCount(site);
},
missingDevicesPercent: (site: Site) => {
return getMissingDevicesCount(site) / (getTotalDevicesCount(site) || 1);
},
errorDevicesCount: (site: Site) => {
return site.validation?.summary.error_devices?.length ?? 0;
return getErrorDevicesCount(site);
},
errorDevicesPercent: (site: Site) => {
return getErrorDevicesCount(site) / (getTotalDevicesCount(site) || 1);
},
extraDevicesCount: (site: Site) => {
return site.validation?.summary.extra_devices?.length ?? 0;
},
lastValidated: (site: Site) => {
return site.validation?.last_updated;
},
percentValidated: async (site: Site, _args, { dataSources: { deviceDS } }: ApolloContext) => {
const validationSummary = site.validation?.summary;

return (
sum([
0,
validationSummary?.correct_devices?.length,
validationSummary?.missing_devices?.length,
validationSummary?.error_devices?.length,
validationSummary?.extra_devices?.length,
]) / ((await deviceDS.getDevicesBySite(site.name)).totalFilteredCount || 1)
);
},
deviceErrors: (site: Site, _args, { dataSources: { deviceDS } }: ApolloContext) => {
return deviceDS.getDeviceErrorsBySite(site.name);
},
Expand Down
12 changes: 9 additions & 3 deletions udmif/api/src/site/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ type DeviceError {
type Site {
# Name of the site
name: String!
# Total number of devices associated to the site
# Total devices seen by UDMIF on the site
seenDevicesCount: Int!
# Total number of devices on the site; correct + missing + error
totalDevicesCount: Int!
# Number of correct devices in the message
correctDevicesCount: Int!
# Percent of correct devices in the message
correctDevicesPercent: Float!
# Number of missing devices in the message
missingDevicesCount: Int!
# Percent of error devices in the message
missingDevicesPercent: Float!
# Number of error devices in the message
errorDevicesCount: Int!
# Percent of extra devices in the message
errorDevicesPercent: Float!
# Number of extra devices in the message
extraDevicesCount: Int!
# Last time the validation message was updated
lastValidated: String
# Percent of devices validated i.e. 0.97
percentValidated: Float!
# Total number of errors across all devices
deviceErrors: [DeviceError!]!
# Total number of errors across all devices
Expand Down
17 changes: 17 additions & 0 deletions udmif/api/src/site/siteUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Site } from './model';

export const getCorrectDevicesCount = (site: Site): number => {
return site.validation?.summary?.correct_devices?.length ?? 0;
};

export const getMissingDevicesCount = (site: Site): number => {
return site.validation?.summary?.missing_devices?.length ?? 0;
};

export const getErrorDevicesCount = (site: Site): number => {
return site.validation?.summary?.error_devices?.length ?? 0;
};

export const getTotalDevicesCount = (site: Site): number => {
return getCorrectDevicesCount(site) + getMissingDevicesCount(site) + getErrorDevicesCount(site);
};
1 change: 0 additions & 1 deletion udmif/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
}
},
Expand Down
11 changes: 7 additions & 4 deletions udmif/event-handler/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ globalConfig.json
# System files
.DS_Store

# environment variables
# Environment variables
setupEnv.sh

# mongo output
# Mongo output
.mongodb

#Build specific files
# Build specific files
dist/
credentials.json
credentials.json

# Test output
test-report.html
Loading