1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 | import {
AuthenticationJWTTokenApi,
DataSetsApi,
HttpBearerAuth,
ProjectResourcesDataSetsApi,
ProjectResourcesWidgetsApi,
ProjectsApi,
PublicTemporalRangeFilterDTO,
PublicVisualAnalyticsDataSetProperties,
PublicVisualAnalyticsGriddedDisplayOptions,
PublicVisualAnalyticsNamedHeatmapDTO,
PublicVisualAnalyticsSingleTimelineProperty,
PublicVisualAnalyticsWidgetProperties,
} from "./gen/api";
const userName = "replace with your API user name";
const password = "replace with your API user password";
async function getJWTToken() {
const authenticationApi = new AuthenticationJWTTokenApi();
return await authenticationApi
.obtainToken({
userName: userName,
password: password,
})
.then((r) => {
return r.body.jwtToken;
})
.catch((reason) => {
console.log(reason);
return null;
});
}
getJWTToken().then(async (token) => {
console.log("Got access token : " + token);
if (token == null) {
return;
}
//Use the obtained JWT token to create an authentication object
const authentication = new HttpBearerAuth();
authentication.accessToken = token;
const dataSetsApi = new DataSetsApi();
//Make sure all requests to the server use the JWT token
dataSetsApi.setDefaultAuthentication(authentication);
//Query for all the datasets
const dataSets = (await dataSetsApi.getAllDataSets()).body;
console.log(dataSets);
const projectsApi = new ProjectsApi();
projectsApi.setDefaultAuthentication(authentication);
//Create a new project
const project = (
await projectsApi.createProject({
name: "My first project",
description: "My first project created through the REST API",
})
).body;
console.log(project);
const projectResourcesDataSetsApi = new ProjectResourcesDataSetsApi();
projectResourcesDataSetsApi.setDefaultAuthentication(authentication);
//Add the dataset to the project
await projectResourcesDataSetsApi.addDataSetToProject(project.id, {
dataSetId: dataSets[0].id,
});
const projectResourcesWidgetsApi = new ProjectResourcesWidgetsApi();
projectResourcesWidgetsApi.setDefaultAuthentication(authentication);
//Widgets can only be added to a group, so first create a new WidgetGroup
const widgetGroup = (
await projectResourcesWidgetsApi.createWidgetGroup(project.id, {
name: "My API created widget group",
})
).body;
//Create the properties for the dataset
const propertiesPerDataSet: Record<
string,
PublicVisualAnalyticsDataSetProperties
> = {};
propertiesPerDataSet[dataSets[0].id] = {
griddedDisplayOptions: {
mode: PublicVisualAnalyticsGriddedDisplayOptions.ModeEnum.NumberOfRecords,
colorByNumberOfRecordsColorMap: {
heatMap: {
name: PublicVisualAnalyticsNamedHeatmapDTO.NameEnum.Rainbow,
},
},
},
};
//Then add a Visual Analytics widget to the group
await projectResourcesWidgetsApi.createVisualAnalyticsWidget(
project.id,
widgetGroup.id,
{
title: "Map fitted on entire area",
properties: {
widgetType:
PublicVisualAnalyticsWidgetProperties.WidgetTypeEnum.SpatialMap,
mapIndex: 0,
},
state: {
individualMapStates: [
{
temporalRangeFilter: {
endTimeType:
PublicTemporalRangeFilterDTO.EndTimeTypeEnum.BeforeEndOfData,
endTimeDeltaInSeconds: 0,
startTimeType:
PublicTemporalRangeFilterDTO.StartTimeTypeEnum
.BeforeEndOfFilter,
startTimeDeltaInSeconds: 60 * 60 * 24 * 7,
endTimeInSeconds: 0,
startTimeInSeconds: 0,
},
dataSetProperties: propertiesPerDataSet,
timeLineProperties: {
properties: [
{
dataSetId: dataSets[0].id,
mode:
PublicVisualAnalyticsSingleTimelineProperty.ModeEnum
.NumberOfAssets,
},
],
},
},
],
},
}
);
});
|