Skip to content

Commit

Permalink
cleanup + update parts of README (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
melodychn authored Sep 4, 2020
1 parent 91cfca9 commit 54a78c3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
47 changes: 31 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# GreySwan

## Config frontend project
Run `yarn` in `./frontend` to install dependencies.

## Run locally
## Run project locally
```
// From frontend directory
yarn local
Expand All @@ -12,6 +9,34 @@ mvn appengine:run
// From python directory
python3.7 main.py
```
*See `key.json` section if you don't already have the key locally.

## Project set up
### Frontend
1) Install Node v10.21.0.
```
nvm install v10.21.0
nvm list // Make sure v10.21.0 is included.
nvm use 10.21.0
```
2) Make sure you have `yarn` installed.
3) Run `yarn` in `./frontend` to install dependencies.
### Java Backend
1) Follow [instructions](https://cloud.google.com/sdk/docs/downloads-apt-ge) to install gCloud SDK.
2) Run `gcloud init` in root directory of our repository. Provide `greyswan` as gCloud project ID.
3) Install Maven locally.
```
sudo apt update
sudo apt install maven
mvn -version // Check if maven is installed.
```
4) Make sure you have Java 8 installed locally. If not, follow instructions [here](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html).
### Python Microservice
1) Make sure you have Python 3.7 and pip3 installed.
2) To install dependencies:
```
pip3 install -r requirements.txt
```

## Testing
```
Expand All @@ -21,18 +46,8 @@ mvn test
yarn test
```

## Setting up and running Python code
To install dependencies: (Only need to run once.)
```
pip3 install -r requirements.txt
```
To run server locally (make sure you're in `python` directory and `key.json` is present):
```
python3.7 main.py
```

## Deploy to gcloud
Only need to do for first time. If you're using cloud shell, should not need following commands.
## Deploy to gCloud
Only need to do for first time in project root directory. If you're using cloud shell, should not need following commands.
```
gcloud init
gcloud config set project greyswan
Expand Down
4 changes: 4 additions & 0 deletions backend/src/main/java/com/google/blackswan/mock/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

/** Constants used throughout the blackswan mock classes. */
public final class Constant {
// Only set to false, when you're pushing to Github or do
// not have access to key.json.
public static final boolean USE_CLOUD_STORAGE = false;

// Constants used to filenames.
private static final String FILE_DELIMITER = "-";
private static final String FILE_END = "--data.csv";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public class SimpleAnomalyGenerator implements AnomalyGenerator {
private static final int THRESHOLD = 13;
private static final int NUM_POINTS = 5;
/** Ideally the FileSystem should be injected. */
private static final FileSystem FILE_SYSTEM = LocalFileSystem.createSystem();
private static final FileSystem FILE_SYSTEM = Constant.USE_CLOUD_STORAGE ?
CloudFileSystem.createSystem() : LocalFileSystem.createSystem();

private final ImmutableList<Anomaly> anomalies;
private final DataInfo topic;
Expand All @@ -50,8 +51,6 @@ public class SimpleAnomalyGenerator implements AnomalyGenerator {
public static SimpleAnomalyGenerator createGenerator(DataInfo topic) {
return new SimpleAnomalyGenerator(
topic,
// For [push] to git, always use LocalFileSystem, as CloudFileSystem will fail
// unit test without access to key.json.
FILE_SYSTEM.getDataAsStream(topic),
THRESHOLD,
NUM_POINTS
Expand Down Expand Up @@ -101,10 +100,6 @@ private ImmutableList<Anomaly> generateAnomalies(int threshold, int numDataPoint
.collect(ImmutableList.toImmutableList());
}

/**
* TODO: Depending on size of future data, alter algorithm of finding
* associated data points.
*/
private Anomaly createAnomalyFromDataPoint(Timestamp time, int numDataPoints) {

// Convert keys into ArrayList.
Expand Down Expand Up @@ -133,7 +128,8 @@ private Anomaly createAnomalyFromDataPoint(Timestamp time, int numDataPoints) {
listKeys.get(firstDataPointIndex),
listKeys.get(lastDataPointIndex));

return new Anomaly(time, topic.getMetricName(), topic.getDimensionName(), dataPoints, relatedDataList);
return new Anomaly(time, topic.getMetricName(), topic.getDimensionName(),
dataPoints, relatedDataList);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
public class SimpleRelatedDataGenerator implements RelatedDataGenerator {
private static final String CONFIG_USERNAME = "catyu@";
/** Ideally should be injected. Currently, putting as class variable. */
private static final FileSystem FILE_SYSTEM = LocalFileSystem.createSystem();
private static final SimpleRelatedDataGenerator INSTANCE = new SimpleRelatedDataGenerator();
private static final FileSystem FILE_SYSTEM = Constant.USE_CLOUD_STORAGE ?
CloudFileSystem.createSystem() : LocalFileSystem.createSystem();
private static final SimpleRelatedDataGenerator INSTANCE
= new SimpleRelatedDataGenerator();

private Multimap<DataInfo, DataInfoUser> relatedDataMap;
private Map<DataInfo, Map<Timestamp, Integer>> csvDataCache;
Expand Down
7 changes: 5 additions & 2 deletions dispatch.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Rules for dispatch file...
dispatch:
# Route the urls that point to the Java backend's API calls
# Route the urls that point to the Java backend's API calls.
- url: "*/api/v1/*"
service: backend
- url: "*/blackswan/*"
service: backend
# Route all other urls to the React.js frontend
# Route the urls that point to Python backend's API calls.
- url: "*/python/*"
service: python
# Route all other urls to the React.js frontend.
- url: "*/*"
service: default

0 comments on commit 54a78c3

Please sign in to comment.