This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
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 #219 from COS301-SE-2023/dev
Dev
- Loading branch information
Showing
72 changed files
with
35,262 additions
and
700 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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 |
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,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 |
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,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)) | ||
|
Oops, something went wrong.