Skip to content

Commit

Permalink
Release 1.0.1
Browse files Browse the repository at this point in the history
new features:
- earthengine library usage cleaned in the code
- Logo changed
- GEE Library upgraded to 0.1.232 version

Merge branch 'development'
  • Loading branch information
ifoche committed Oct 6, 2020
2 parents 0121e8b + ea58da1 commit 397f066
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 1,513 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ $ yarn build-importer
- `src/locales`: Auto-generated, don't change nor add to version control.
- `cypress/integration/`: Contains the integration Cypress tests.

### Google Earth Engine

The package [@google/earthengine](https://www.npmjs.com/package/@google/earthengine) does not work when minified in the production create-react-app build. For this reason, instead of importing it directly within the app, we use object `window.ee`, loaded at `public/index.html` (`ee_api_js.js`).

To update `@google/earthengine` to a new version, simply run `yarn add -D @google/earthengine@VERSION`.

### i18n

#### Update an existing language
Expand Down
685 changes: 0 additions & 685 deletions ee_api_js.js

This file was deleted.

Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dhis2-gee-app",
"description": "DHIS2 GEE App",
"version": "1.0.0",
"version": "1.0.1",
"license": "GPL-3.0",
"author": "EyeSeeTea team",
"homepage": ".",
Expand All @@ -18,7 +18,6 @@
"@dhis2/d2-ui-forms": "^6.5.3",
"@dhis2/ui-core": "^4.8.0",
"@dhis2/ui-widgets": "^2.0.8",
"@google/earthengine": "^0.1.217",
"@material-ui/core": "^4.9.2",
"@material-ui/icons": "^4.9.1",
"@material-ui/styles": "^4.9.0",
Expand Down Expand Up @@ -68,6 +67,7 @@
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/preset-typescript": "^7.8.3",
"@google/earthengine": "0.1.232",
"@testing-library/jest-dom": "^5.1.1",
"@testing-library/react": "^9.5.0",
"@types/axios-mock-adapter": "^1.10.0",
Expand Down
706 changes: 0 additions & 706 deletions public/ee_api_js.js

This file was deleted.

1 change: 1 addition & 0 deletions public/ee_api_js.js
Binary file modified public/favicon.ico
Binary file not shown.
10 changes: 8 additions & 2 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { SetAsDefaultMappingUseCase } from "./domain/usecases/SetAsDefaultMappin
import { GetGeeDataSetByIdUseCase } from "./domain/usecases/GetGeeDataSetByIdUseCase";
import OrgUnitD2ApiRepository from "./data/OrgUnitD2ApiRepository";
import OrgUnitRepository from "./domain/repositories/OrgUnitRepository";
import { EarthEngine } from "./types/google-earth-engine";

interface Type<T> {
new (...args: any[]): T;
Expand All @@ -55,7 +56,12 @@ class CompositionRoot {
private dependencies = new Map<Token<any>, any>();
private apiVersion: number;

constructor(private d2Api: D2Api, d2Version: string, private config: Config) {
constructor(
private d2Api: D2Api,
private ee: EarthEngine,
d2Version: string,
private config: Config
) {
this.apiVersion = +d2Version.split(".")[1];

this.initializeDataStore();
Expand Down Expand Up @@ -265,7 +271,7 @@ class CompositionRoot {

const orgUnitsRepository = this.dependencies.get("orgUnitRepository") as OrgUnitRepository;

const geeDataRepository = new GeeDataEarthEngineRepository(this.d2Api);
const geeDataRepository = new GeeDataEarthEngineRepository(this.d2Api, this.ee);
const dataValueSetD2ApiRepository = new DataValueSetD2ApiRepository(this.d2Api);
const dataValueSetFileRepository = new DataValueSetFileRepository();
const importSummaryRepository = new ImportSummaryD2ApiRepository(
Expand Down
2 changes: 1 addition & 1 deletion src/data/GeeDataSetD2ApiRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class GeeDataSetFileRepository implements GeeDataSetRepository {
id: id,
imageCollectionId: data.id,
displayName: data.title,
type: data.properties["gee:type"],
type: data.properties["gee:type"] ? data.properties["gee:type"] : data["gee:type"],
description: data.description,
doc: `https://developers.google.com/earth-engine/datasets/catalog/${data.id}`,
cadence: data.properties["gee:cadence"],
Expand Down
18 changes: 7 additions & 11 deletions src/data/GeeDataValueSetApiRepository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EarthEngine } from "./../types/google-earth-engine";
import _ from "lodash";
import moment, { Moment } from "moment";
import {
Expand All @@ -9,7 +10,7 @@ import {
Region,
ImageCollection,
DataSetInfoData,
} from "@google/earthengine";
} from "../types/google-earth-engine";
import {
GeeDataValueSetRepository,
GeeDataFilters,
Expand All @@ -18,15 +19,6 @@ import {
import { GeeDataValueSet, GeeDataValue } from "../domain/entities/GeeDataValueSet";
import { D2Api } from "d2-api";

// -- TODO: gee static ------
declare global {
interface Window {
ee: any;
}
}
const ee = window.ee || {};
//---------------------

type Geometry = GeometryPoint | GeometryPolygon;

export interface GeeCredentials {
Expand All @@ -36,7 +28,7 @@ export interface GeeCredentials {
}

export class GeeDataEarthEngineRepository implements GeeDataValueSetRepository {
constructor(private d2Api: D2Api) {}
constructor(private d2Api: D2Api, private ee: EarthEngine) {}

async getData<Band extends string>(
options: GeeDataFilters<Band>
Expand Down Expand Up @@ -79,6 +71,7 @@ export class GeeDataEarthEngineRepository implements GeeDataValueSetRepository {
engineGeometry: object,
scale: number
): Promise<GeeDataValueSet<Band>> {
const { ee } = this;
const imageCollection = new ee.ImageCollection(id)
.select(bands)
.filterDate(startDate, endDate);
Expand Down Expand Up @@ -113,6 +106,7 @@ export class GeeDataEarthEngineRepository implements GeeDataValueSetRepository {
geometry: GeeGeometry,
engineGeometry: object
): Promise<GeeDataValueSet<Band>> {
const { ee } = this;
const imageCollection = new ee.ImageCollection(id)
.select(bands)
.filterDate(startDate, endDate);
Expand Down Expand Up @@ -148,6 +142,7 @@ export class GeeDataEarthEngineRepository implements GeeDataValueSetRepository {
}

private async initializeEngine() {
const { ee } = this;
const credentials = await this.d2Api.get<GeeCredentials>("/tokens/google").getData();

ee.data.setAuthToken(
Expand All @@ -168,6 +163,7 @@ export class GeeDataEarthEngineRepository implements GeeDataValueSetRepository {
}

private getGeometry(geometry: GeeGeometry): Geometry {
const { ee } = this;
switch (geometry.type) {
case "point":
return ee.Geometry.Point(geometry.coordinates);
Expand Down
93 changes: 0 additions & 93 deletions src/types/google-earth-engine.d.ts

This file was deleted.

87 changes: 87 additions & 0 deletions src/types/google-earth-engine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
export interface EarthEngine {
data: Data;
initialize(): void;

Geometry: Geometry;
Image(s: any): Image;
ImageCollection: {
new (dataSetId: string): ImageCollection;
};
Reducer: {
mean(): any;
};
}

export interface Region {
getInfo(onFinish: (data?: InfoData, error?: string) => void): unknown;
}

export interface ImageCollection {
select(bands: string[]): this;
filterDate(startDate: string, endDater: string): this;
getInfo(onFinish: (data?: DataSetInfoData, error?: string) => void): unknown;
map(image: any): this;
getRegion(geometry: GeometryInstance, scale: number): Region;
}

type PropertiesDictionary = {
[name: string]: any;
};

export type DataSetInfoData = {
type: string;
properties: PropertiesDictionary;
features: DataSetInfoData[];
};

export interface Image {
setMulti(properties: PropertiesDictionary): unknown;
reduceRegion(params: ReduceRegionParams): PropertiesDictionary;
}

export interface ReduceRegionParams {
reducer: Reducer<any, any>;
geometry?: GeometryInstance;
scale?: number;
bestEffort?: boolean;
maxPixels?: number;
tileScale?: number;
}

export interface List {
getInfo(): any[];
}

type Reducer<Input, Output> = (input: Input) => Output;

// [periodId, lon, lat, time, ...number]
export type InfoData = Array<any[]>;

export type Coordinates = [number, number];

export interface Geometry {
Point(coordinates: Coordinates): GeometryPoint;
MultiPolygon(Coordinates: any): GeometryPolygon;
}

export interface Data {
setAuthToken: (
clientId: string,
tokenType: string,
accessToken: string,
expiresIn: number,
extraScopes: Maybe<string[]>,
callback: Maybe<Callback>,
updateAuthLibrary: boolean
) => void;
}

export type GeometryPoint = object;
export type GeometryPolygon = object;
export type GeometryInstance = GeometryPoint | GeometryPolygon;

// [periodId, lon, lat, time]
export type InfoDataRowBase = [string, number, number, number];

type Maybe<T> = T | undefined | null;
type Callback = () => void;
14 changes: 5 additions & 9 deletions src/webapp/components/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ import { Config } from "../../models/Config";
import { User } from "../../models/User";
import { LinearProgress } from "@material-ui/core";
import CompositionRoot from "../../../CompositionRoot";

// -- TODO: gee static ------
// import ee from "@google/earthengine";
import { EarthEngine } from "../../../types/google-earth-engine";

declare global {
interface Window {
ee: any;
ee: EarthEngine;
}
}
const ee = window.ee || {};
//---------------------

type D2 = object;

type AppWindow = Window & {
Expand Down Expand Up @@ -92,8 +87,9 @@ const App = () => {
]);

const version = (await api.system.info.getData()).version;
if (!window.ee) throw new Error("Google Earth Engine not found (window.ee)");

const compositionRoot = new CompositionRoot(api, version, config);
const compositionRoot = new CompositionRoot(api, window.ee, version, config);

const dataImporter: boolean = process.env.REACT_APP_DATA_IMPORTER
? process.env.REACT_APP_DATA_IMPORTER === "true"
Expand All @@ -110,7 +106,7 @@ const App = () => {
};
setAppContext(appContext);
// Google Earth Engine must be defined globally in window (as var 'ee') to work
Object.assign(window, { app: appContext, ee });
Object.assign(window, { app: appContext });

setShowShareButton(_(appConfig).get("appearance.showShareButton") || false);
if (currentUser.canReportFeedback()) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1146,10 +1146,10 @@
resolved "https://registry.npmjs.org/@emotion/hash/-/hash-0.7.4.tgz#f14932887422c9056b15a8d222a9074a7dfa2831"
integrity sha512-fxfMSBMX3tlIbKUdtGKxqB1fyrH6gVrX39Gsv3y8lRYKUqlgDt3UMqQyGnR1bQMa2B8aGnhLZokZgg8vT0Le+A==

"@google/earthengine@^0.1.217":
version "0.1.217"
resolved "https://registry.npmjs.org/@google/earthengine/-/earthengine-0.1.217.tgz#077a61286a2ca81d250ffab77d3a87f9b8a5e230"
integrity sha512-CpIyccte1tKs06rLNuUmfan9HHSugoVVRk8vlxYyCqpFzGvxQB8pc83sduDVClrgQHdH5gyYJq2l1mJDLxjSEg==
"@google/[email protected].232":
version "0.1.232"
resolved "https://registry.yarnpkg.com/@google/earthengine/-/earthengine-0.1.232.tgz#98a5ef9e3e8f74c83921840aa9a3eed51a87df22"
integrity sha512-0WfQi7uQbL+0f2wvX6D88aK53eSmyxbbiQRy62Z+FVG9gojQg54YMeZ2MWkv3E0S60edC5Zyq6meFMG6lG3Ndg==
dependencies:
googleapis "^42.0.0"
xmlhttprequest "^1.8.0"
Expand Down

0 comments on commit 397f066

Please sign in to comment.