-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from EyeSeeTea/development
Release 0.1.0
- Loading branch information
Showing
23 changed files
with
12,292 additions
and
1,743 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { D2ApiResponse, HttpResponse } from "./common"; | ||
import { D2Api } from "./d2-api"; | ||
|
||
type Operator = "EQ" | "GT" | "GE" | "LT" | "LE"; | ||
|
||
export type AnalyticsOptions = { | ||
dimension: string[]; | ||
filter?: string[]; | ||
aggregationType?: | ||
| "SUM" | ||
| "AVERAGE" | ||
| "AVERAGE_SUM_ORG_UNIT" | ||
| "LAST" | ||
| "LAST_AVERAGE_ORG_UNIT" | ||
| "COUNT" | ||
| "STDDEV" | ||
| "VARIANCE" | ||
| "MIN" | ||
| "MAX"; | ||
measureCriteria?: Operator; | ||
preAggregationMeasureCriteria?: Operator; | ||
startDate?: string; | ||
endDate?: string; | ||
skipMeta?: boolean; | ||
skipData?: boolean; | ||
skipRounding?: boolean; | ||
hierarchyMeta?: boolean; | ||
ignoreLimit?: boolean; | ||
tableLayout?: boolean; | ||
hideEmptyRows?: boolean; | ||
hideEmptyColumns?: boolean; | ||
showHierarchy?: boolean; | ||
includeNumDen?: boolean; | ||
includeMetadataDetails?: boolean; | ||
displayProperty?: "NAME" | "SHORTNAME"; | ||
outputIdScheme?: string; | ||
inputIdScheme?: string; | ||
approvalLevel?: string; | ||
relativePeriodDate?: string; | ||
userOrgUnit?: string; | ||
columns?: string; | ||
rows?: string; | ||
order?: "ASC" | "DESC"; | ||
timeField?: string; | ||
orgUnitField?: string; | ||
}; | ||
|
||
export type AnalyticsResponse = { | ||
headers: Array<{ | ||
name: "dx" | "dy"; | ||
column: "Data"; | ||
valueType: "TEXT" | "NUMBER"; | ||
type: "java.lang.String" | "java.lang.Double"; | ||
hidden: boolean; | ||
meta: boolean; | ||
}>; | ||
|
||
rows: Array<string[]>; | ||
width: number; | ||
height: number; | ||
}; | ||
|
||
export type RunAnalyticsResponse = HttpResponse<{ | ||
id: string; | ||
created: string; | ||
name: "inMemoryAnalyticsJob"; | ||
jobType: "ANALYTICS_TABLE"; | ||
jobStatus: "SCHEDULED"; | ||
jobParameters: { | ||
skipResourceTables: boolean; | ||
}; | ||
relativeNotifierEndpoint: string; | ||
}>; | ||
|
||
export default class Analytics { | ||
constructor(public d2Api: D2Api) {} | ||
|
||
get(options: AnalyticsOptions): D2ApiResponse<AnalyticsResponse> { | ||
return this.d2Api.get<AnalyticsResponse>("/analytics", options); | ||
} | ||
|
||
run(): D2ApiResponse<RunAnalyticsResponse> { | ||
return this.d2Api.post<RunAnalyticsResponse>("/resourceTables/analytics"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Canceler } from "axios"; | ||
import { D2Response } from "./common"; | ||
|
||
export class D2ApiResponse<Data> { | ||
constructor(public cancel: Canceler, public response: Promise<D2Response<Data>>) {} | ||
|
||
static build<Data_>({ | ||
cancel, | ||
response, | ||
}: { | ||
cancel?: Canceler; | ||
response: Promise<D2Response<Data_>>; | ||
}): D2ApiResponse<Data_> { | ||
return new D2ApiResponse(cancel || noop, response); | ||
} | ||
|
||
getData() { | ||
return this.response.then(({ data }) => data); | ||
} | ||
|
||
map<MappedData>(mapper: (response: D2Response<Data>) => MappedData): D2ApiResponse<MappedData> { | ||
const { cancel, response } = this; | ||
const mappedResponse = response.then( | ||
(response_: D2Response<Data>): D2Response<MappedData> => ({ | ||
...response_, | ||
data: mapper(response_), | ||
}) | ||
); | ||
|
||
return new D2ApiResponse<MappedData>(cancel, mappedResponse); | ||
} | ||
|
||
flatMap<MappedData>( | ||
mapper: (response: D2Response<Data>) => D2ApiResponse<MappedData> | ||
): D2ApiResponse<MappedData> { | ||
const { cancel, response } = this; | ||
let cancel2: Canceler | undefined; | ||
|
||
const mappedResponse = response.then(response_ => { | ||
const res2 = mapper(response_); | ||
cancel2 = res2.cancel; | ||
return res2.response; | ||
}); | ||
|
||
function cancelAll() { | ||
cancel(); | ||
if (cancel2) cancel2(); | ||
} | ||
|
||
return new D2ApiResponse<MappedData>(cancelAll, mappedResponse); | ||
} | ||
} | ||
|
||
const noop = () => { | ||
return; | ||
}; |
Oops, something went wrong.