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

Commit

Permalink
Merge pull request #219 from COS301-SE-2023/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
u18004874 authored Sep 26, 2023
2 parents d7bb01e + 65274ad commit 92520b0
Show file tree
Hide file tree
Showing 72 changed files with 35,262 additions and 700 deletions.
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
34 changes: 33 additions & 1 deletion api/scripts/fetchstatstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import json
import requests

testing_endpoint = "http://witpa.codelog.co.za/api/fetchSuburbStats"
testing_endpoint = "http://127.0.0.1:8000/api/fetchSuburbStats"
testing_endpoint = "https://witpa.codelog.co.za/api/fetchSuburbStats"
schedule_endpoint = "https://witpa.codelog.co.za/api/fetchScheduleData"
schedule_endpoint = "http://127.0.0.1:8000/api/fetchScheduleData"
maponoff_endpoint = "http://127.0.0.1:8000/api/fetchTimeForPolygon"
def sendRequest():
body = {
"suburbId" : 17959
Expand All @@ -15,5 +18,34 @@ def sendRequest():
response = requests.post(url=testing_endpoint,data=request,headers=headers)
print(response.text)

def sendScheduleRequest():
body = {
#"suburbId" :18231
"suburbId" : 18210
}
request = json.dumps(body)
headers = {
"Content-Type":"application/json"
}
response = requests.post(url=schedule_endpoint,data=request,headers=headers)
print(response.text)

def sendTimeForPolygonRequest():
body = {
#"suburbId" :18057
#"suburbId" : 18231
"suburbId" : 18195
}
request = json.dumps(body)
headers = {
"Content-Type":"application/json"
}
response = requests.post(url=maponoff_endpoint,data=request,headers=headers)
print(response.text)
if (__name__ == "__main__"):
sendRequest()
print("=================================================================================")
sendScheduleRequest()
print("=================================================================================")
sendTimeForPolygonRequest()

2 changes: 1 addition & 1 deletion api/scripts/mapdatatest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import json
import requests

testing_endpoint = "https://witpa.codelog.co.za/api/fetchMapData"
testing_endpoint = "http://127.0.0.1:8000/api/fetchMapData"
testing_endpoint = "https://witpa.codelog.co.za/api/fetchMapData"
def sendRequest():
body = {
"bottomLeft": [-90,-180],
Expand Down
84 changes: 84 additions & 0 deletions api/scripts/robots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import requests
import json

def get_polygons():
api_url = 'https://witpa.codelog.co.za/api/fetchMapData'

# Define the request payload (body)
body = {
"bottomLeft": [-90, -180],
"topRight": [90, 180]
}

# Send a POST request to the API
witpaData = requests.post(api_url, json=body).json()

polygons = []
for feature in witpaData['result']['mapPolygons'][0]['features']:
poly_cords = [point for point in feature['geometry']['coordinates'][0] if len(point) == 2]
sub_polygon = [point for point in feature['geometry']['coordinates'][0] if len(point) > 2]
polygon = {
"id" : feature['id'],
"coordinates" : poly_cords,
"robots" : []
}
polygons.append(polygon)
return polygons

def point_in_polygon(point, polygon):
x, y = point

# Check if the point is outside the bounding box of the polygon
if(len(polygon) == 0):
return False
min_x, min_y = min(polygon, key=lambda p: p[0])
max_x, max_y = max(polygon, key=lambda p: p[0])

if x < min_x or x > max_x or y < min_y or y > max_y:
return False

# Check if the point is inside the polygon using ray-casting algorithm
inside = False
n = len(polygon)
j = n - 1

for i in range(n):
xi, yi = polygon[i]
xj, yj = polygon[j]

if ((yi > y) != (yj > y)) and (x < (xj - xi) * (y - yi) / (yj - yi) + xi):
inside = not inside

j = i
return inside

def get_robots():
robots = []
# Open the file in read mode
with open("robots.txt", 'r') as file:
for line in file:
lon,lat = line.strip().split(',')
robots.append([float(lon),float(lat)]) # Use strip() to remove leading/trailing whitespace
return robots

polygons = get_polygons()
robots = get_robots()

output = {
"robots" : [{}]
}

for polygon in polygons:
data = {
"coordinates": [],
"polygon_id": polygon["id"]
}
for robot in robots:
if point_in_polygon(robot,polygon["coordinates"]):
print("yes!")
data["coordinates"].append(robot)
output["robots"].append(data)

with open("robots.json", "w") as json_file:
json_file.write(json.dumps(output, indent=2))

Loading

0 comments on commit 92520b0

Please sign in to comment.