Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Merge branch 'dev' into Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Radloff committed Sep 28, 2023
2 parents 209f47b + fa24298 commit b41d3b4
Show file tree
Hide file tree
Showing 50 changed files with 982 additions and 344 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/app-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
branches:
- main
- dev
push:
branches:
- dev

jobs:
test:
Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/firebase-hosting-pull-request.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/firebase_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and Deploy app to DEV site
'on':
push:
branches:
- dev

jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: "18"

- name: Install Dependencies
working-directory: ./app/WhereIsThePower
run: npm install --frozen-lock

- name: Inject Developer tags
run: |
sed -i 's|<!-- DEVELOPER SITE INJECTION -->|<ion-item><ion-title style="background-color: red; color: white;">DEVELOPER SITE</ion-title></ion-item>|g' app/WhereIsThePower/src/app/app.component.html
sed -i 's|<title>Where Is The Power|<title>WITP-DEV|g' app/WhereIsThePower/src/index.html
sed -i 's|href="assets/icon/favicon.ico"|href="assets/Ramp.svg"|g' app/WhereIsThePower/src/index.html
- name: update Prod ENV file
run: |
sed -i 's/HelloAPIKey/${{ secrets.MAPBOX_API_KEY }}/g' app/WhereIsThePower/src/environments/environment.prod.ts
- name: Build app
working-directory: ./app/WhereIsThePower
run: npm run build

- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_WHEREISTHEPOWER_33A66 }}'
channelId: live
projectId: whereisthepower-33a66
target: dev
entrypoint: ./app/WhereIsThePower
39 changes: 39 additions & 0 deletions .github/workflows/firebase_prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build and Deploy app to PROD site
'on':
push:
branches:
- main

jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: "18"

- name: Install Dependencies
working-directory: ./app/WhereIsThePower
run: npm install --frozen-lock

- name: Remove consolelogs from production site
run: echo "if(window) { window.console.log = function() {}; }" >> app/WhereIsThePower/src/main.ts

- name: update Prod ENV file
run: |
sed -i 's/HelloAPIKey/${{ secrets.MAPBOX_API_KEY }}/g' app/WhereIsThePower/src/environments/environment.prod.ts
- name: Build app
working-directory: ./app/WhereIsThePower
run: npm run build

- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_WHEREISTHEPOWER_33A66 }}'
channelId: live
projectId: whereisthepower-33a66
target: prod
entrypoint: ./app/WhereIsThePower
21 changes: 12 additions & 9 deletions api/src/ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use utoipa::ToSchema;
#[utoipa::path(post, tag = "AI", path = "/api/ai/info", request_body = AiInfoRequest)]
#[post("/ai/info", format = "application/json", data = "<request>")]
pub async fn get_ai_info<'a>(request: Json<AiInfoRequest>) -> ApiResponse<'a, AiInfoResponse> {
let mapbox_api_key = if let Ok(key) = env::var("MAPBOX_API_KEY") {
let mapbox_api_key = if let Ok(key) = dbg!(env::var("MAPBOX_API_KEY")) {
key
} else {
log::error!("We couldn't get the mapbox api key. The environment variable was not set!");
Expand All @@ -21,11 +21,12 @@ pub async fn get_ai_info<'a>(request: Json<AiInfoRequest>) -> ApiResponse<'a, Ai

match Command::new("python3")
.args([
"src/avoid_cords.py",
"route.py",
serde_json::to_string(&request.into_inner())
.unwrap()
.as_ref(),
])
.current_dir("src")
.stdout(Stdio::piped())
.env("MAPBOX_API_KEY", mapbox_api_key)
.output()
Expand Down Expand Up @@ -56,19 +57,21 @@ pub async fn get_ai_info<'a>(request: Json<AiInfoRequest>) -> ApiResponse<'a, Ai
#[derive(Clone, Deserialize, Serialize, ToSchema)]
#[schema(example = json! {
AiInfoRequest {
polygon: vec![
[0.0, 0.0],
[90.0, -90.0],
[-90.0, 90.0],
]
origin: Box::new([28.3, -27.73]),
destination: Box::new([28.2651, -25.7597])
}
})]
pub struct AiInfoRequest {
pub polygon: Vec<[f64; 2]>,
pub origin: Box<[f64; 2]>,
pub destination: Box<[f64; 2]>,
}

#[derive(Clone, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AiInfoResponse {
pub coords_to_avoid: Vec<[f64; 2]>,
pub duration: f32,
pub distance: f32,
pub traffic_lights_avoided: Vec<[f32; 2]>,
pub instructions: Vec<String>,
pub coordinates: Vec<[f32; 2]>,
}
17 changes: 17 additions & 0 deletions api/src/loadshedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rocket::{
fairing::{self, Fairing, Info, Kind},
futures::{future::try_join_all, TryStreamExt},
post,
get,
serde::json::Json,
Orbit, Rocket, State,
};
Expand Down Expand Up @@ -193,6 +194,22 @@ pub async fn fetch_time_for_polygon<'a>(
}
}

#[utoipa::path(get, path = "/api/fetchCurrentStage")]
#[get("/fetchCurrentStage")]
pub async fn get_current_stage<'a>(
loadshedding_stage: &State<Option<Arc<RwLock<LoadSheddingStage>>>>,
) -> ApiResponse<'a, i32> {
// query end
ApiResponse::Ok(loadshedding_stage
.inner()
.as_ref()
.clone()
.unwrap()
.read()
.await
.stage)
}

#[derive(Debug, Serialize, Deserialize, Clone, Entity)]
#[serde(rename_all = "camelCase")]
#[collection_name = "stage_log"]
Expand Down
10 changes: 7 additions & 3 deletions api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const DB_NAME: &'static str = "wip";
#[openapi(
paths(
user::create_user,
loadshedding::get_current_stage,
loadshedding::fetch_map_data,
loadshedding::fetch_schedule,
loadshedding::fetch_suburb_stats,
Expand Down Expand Up @@ -182,6 +183,10 @@ async fn get_config() -> Figment {
}

async fn build_rocket() -> Rocket<Build> {
if let Err(err) = dotenvy::dotenv() {
warn!("Couldn't read .env file! {err:?}");
}

let figment = get_config().await;
let db_uri = env::var("DATABASE_URI").unwrap_or(String::from(""));
// Cors Options, we should modify to our needs but leave as default for now.
Expand Down Expand Up @@ -218,6 +223,7 @@ async fn build_rocket() -> Rocket<Build> {
routes!(
auth::authenticate,
user::create_user,
loadshedding::get_current_stage,
loadshedding::fetch_map_data,
loadshedding::fetch_suburb_stats,
loadshedding::fetch_schedule,
Expand Down Expand Up @@ -253,6 +259,7 @@ async fn build_rocket() -> Rocket<Build> {
routes!(
auth::authenticate,
user::create_user,
loadshedding::get_current_stage,
loadshedding::fetch_map_data,
loadshedding::fetch_suburb_stats,
loadshedding::fetch_schedule,
Expand Down Expand Up @@ -285,9 +292,6 @@ async fn build_rocket() -> Rocket<Build> {
async fn main() -> Result<(), rocket::Error> {
setup_logger().expect("Couldn't setup logger!");

if let Err(err) = dotenvy::dotenv() {
warn!("Couldn't read .env file! {err:?}");
}
if let Err(err) = dns::update_dns().await {
warn!("Couldn't setup DNS: {err:?}");
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import requests
import json

import os

congestion_levels = {
"low": 1,
Expand Down
5 changes: 4 additions & 1 deletion api/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ async fn test_ai_endpoint() {
let response = client
.post(format!("/api{}", uri!(super::ai::get_ai_info)))
.header(ContentType::JSON)
.json(&AiInfoRequest { polygon: vec![] })
.json(&AiInfoRequest {
origin: Box::new([28.3, -27.73]),
destination: Box::new([28.2651, -25.7597]),
})
.dispatch()
.await;

Expand Down
17 changes: 15 additions & 2 deletions app/WhereIsThePower/.firebaserc
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"projects": {
"default": "whereisthepower-33a66"
}
}
},
"targets": {
"whereisthepower-33a66": {
"hosting": {
"prod": [
"whereisthepower-33a66"
],
"dev": [
"whereisthepowerdev"
]
}
}
},
"etags": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
<!-- Permissions -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
49 changes: 48 additions & 1 deletion app/WhereIsThePower/firebase.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
{
"hosting": {
"hosting":[
{
"target": "prod",
"public": "www",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"headers": [
{
"source": "**",
"headers": [
{
"key": "Cache-Control",
"value": "no-cache, no-store, must-revalidate"
}
]
},
{
"source": "**/*.@(jpg|jpeg|gif|png|svg|webp|js|css|eot|otf|ttf|ttc|woff|font.css)",
"headers": [
{
"key": "Cache-Control",
"value": "no-cache"
}
]
},
{
"source": "ngsw-worker.js",
"headers": [
{
"key": "Cache-Control",
"value": "no-cache"
}
]
}
]
},
{
"target": "dev",
"public": "www",
"ignore": [
"firebase.json",
Expand Down Expand Up @@ -42,4 +88,5 @@
}
]
}
]
}
2 changes: 1 addition & 1 deletion app/WhereIsThePower/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@angular/compiler": "^16.0.0",
"@angular/compiler-cli": "^16.0.0",
"@angular/language-service": "^16.0.0",
"@capacitor/assets": "^2.0.4",
"@capacitor/assets": "^3.0.0",
"@capacitor/cli": "5.2.2",
"@cypress/schematic": "^2.5.0",
"@ionic/angular-toolkit": "^9.0.0",
Expand Down
2 changes: 2 additions & 0 deletions app/WhereIsThePower/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ <h2>Where is the Power?</h2>
<ion-icon slot="start" name="person-circle"></ion-icon>
<ion-label>Profile</ion-label>
</ion-item>

<!-- DEVELOPER SITE INJECTION -->
</ion-menu-toggle>
</ion-list>
</ion-content>
Expand Down
Loading

0 comments on commit b41d3b4

Please sign in to comment.