Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create onboarding #1

Merged
merged 27 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9b03456
Add style guide and link to notion doc in README
Yarik-Popov Sep 28, 2024
6960a2b
Edit .gitignore
Yarik-Popov Sep 28, 2024
a4b9cb5
Setup python
Yarik-Popov Sep 28, 2024
bc0037e
Create structure of backend
Yarik-Popov Sep 28, 2024
e1238ce
Continue
Yarik-Popov Sep 29, 2024
ca3fa7f
Create models
Yarik-Popov Oct 2, 2024
decfd4d
Add model validator for MainCommand
Yarik-Popov Oct 3, 2024
2357d02
Init frontend
Yarik-Popov Oct 3, 2024
c068085
Restructure api directory
Yarik-Popov Oct 4, 2024
4b67126
Create test for setup
Yarik-Popov Oct 4, 2024
86bb6c9
Continue on backend
Yarik-Popov Oct 5, 2024
bb57c45
Add workflows
Yarik-Popov Oct 5, 2024
01339c1
Add PR template
Yarik-Popov Oct 5, 2024
d2069f2
Add naming convention for frontend and package-lock.json
Yarik-Popov Oct 5, 2024
a6b16a1
Continue on frontend
Yarik-Popov Oct 5, 2024
943782a
Move endpoints around, add main-command get
Yarik-Popov Oct 5, 2024
a251cf0
Setup basic input form and seperate requests/responses
Yarik-Popov Oct 5, 2024
db19eb4
Create table
Yarik-Popov Oct 5, 2024
54ff635
Add mock data to backend
Yarik-Popov Oct 6, 2024
863b3bf
Add logging and refactor setup
Yarik-Popov Oct 6, 2024
b2142ee
Finish setup of frontend
Yarik-Popov Oct 6, 2024
9765b94
Add comments and rename functions
Yarik-Popov Oct 6, 2024
7ae3aab
Add model validation tests for MainCommand
Yarik-Popov Oct 6, 2024
c67647e
Add get commands test
Yarik-Popov Nov 4, 2024
b124460
Add create test
Yarik-Popov Nov 4, 2024
1af7f77
Add delete and main command tests
Yarik-Popov Nov 4, 2024
36634bb
Clean up
Yarik-Popov Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Purpose
Completed the GS on-boarding task. Include a screenshot of the front-end of the application.

# New Changes
- Explain new changes

# Testing
- Explain tests that you ran to verify code functionality.
- Any functions that can be unit-tested should include a unit test in the PR. Otherwise, explain why it cannot be unit-tested.

# Outstanding Changes
- If there are non-critical changes (i.e. additional features) that can be made to this feature in the future, indicate them here.
26 changes: 26 additions & 0 deletions .github/workflows/frontend_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Frontend Build
on:
pull_request:
push:
branches:
- main

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install dependencies for frontend
run: |
cd frontend
npm ci
- name: Build project
run: |
cd frontend
npm run build
34 changes: 34 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Pytest

on:
pull_request:
push:
branches:
- main

jobs:
pytest:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ['3.10']

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -e .

- name: Run pytest
run: |
python -m pytest
47 changes: 36 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Backend:

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -55,16 +57,6 @@ cover/
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

Expand Down Expand Up @@ -159,4 +151,37 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

# IDEs
compile_commands.json
.cache/

### Frontend:
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Dependencies
*node_modules
*.pnp
.pnp.js

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# Build
*dist
*dist-ssr
*.local

# Db
*.db
215 changes: 213 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,213 @@
# GS-Onboarding
Ground station onboarding for the firmware sub-team
# GS Onboarding Challenge
Welcome to Orbital's Ground Station Onboarding Challenge! Please visit this [Notion doc](https://www.notion.so/uworbital/Ground-Station-Onboarding-10f8a26d767780d7ae8de921d9782b77) for the challenge instructions. Remember to follow our style guide which is written below.

## Python Style Guide

- We will be following the Python language style guide [PEP8](https://peps.python.org/pep-0008/)
- If there are any discrepancies between this style guide and PEP8, this style guide takes precedence.

### Type Hinting Convention

All function and method parameters (except for the `self` and `cls` parameters) and return signatures should be type hinted.

```python
def my_add(num1: int, num2: int) -> int:
"""
@brief Adds two numbers together

@param num1 - The first number to add.
@param num2 - The second number to add.
@return Returns the sum of the two numbers.
"""
return num1 + num2
```

### Comments

### Naming Conventions

- `variable_names`, `field_names` and `function_constants` in snake_case
- `_private_field_names`, and `_private_method_names()` in \_snake_case
- `function_names()` and `method_names()` in snake_case
- `CONSTANT_NAMES: Final` and `ENUM_OPTIONS` in CAPITAL_SNAKE_CASE for module and class constants (not for local constant)
- `file_names` in snake_case
- `ClassName` in PascalCase
```python
# For brevity, the class comments were removed but they should be in real code
import dataclasses

@dataclasses.dataclass
class PointTwoDimension:
x: int
y: int

class PointTwoDimension:
def __init__(x: int, y: int):
self.x = x
self.y = y
```

- `EnumName` in PascalCase

```python
import enum

class ErrorCode(enum.Enum):
SUCCESS = 0
INVALID_ARG = 1

# Accessing:
ErrorCode.SUCCESS # <ErrorCode.SUCCESS: 0>
ErrorCode.INVALID_ARG # <ErrorCode.INVALID_ARG: 1>
```

#### Single Line Comments

Variable and function names should be descriptive enough to understand even without comments. Comments are needed to describe any complicated logic. Use `#` for single-line comments.

#### Function and Method Comments

Function and method comments using `""" """` should exist below the function declaration. For methods, the `self` or `cls` parameter does not require a description.

```python
def my_add(num1: int, num2: int) -> int:
"""
@brief Adds two numbers together

@param num1 - The first number to add.
@param num2 - The second number to add.
@return Returns the sum of the two numbers.
"""
return num1 + num2
```

```python
def increase_x(self, count: int) -> None:
"""
@brief Increases the x attribute by the count.

@param count - Count to increase the x attribute by.
"""
self.x += count
```

#### File Header Comments

File comments are not required

#### Class Comments

- Class comments should exist after the class definition
- Provide a brief description given class purpose
- Provide a section in the class comment listing the attributes, their type and purpose
- Enum class comments do not require listing the attributes

```python
class PointTwoDimension:
"""
@brief Class for storing a 2D point
@attribute x (int) - x coordinate of the point
@attribute y (int) - y coordinate of the point
"""

def __init__(x: int, y: int):
self.x = x
self.y = y

@dataclasses.dataclass
class PointTwoDimension:
"""
@brief Class for storing a 2D point
@attribute x (int) - x coordinate of the point
@attribute y (int) - y coordinate of the point
"""

x: int
y: int
```
```python
import enum

# No comments required
class ErrorCode(enum.Enum):
"""
@brief Enum for the error codes
"""

SUCCESS = 0
INVALID_ARG = 1
```

### Imports

#### Grouping Imports

Handled by pre-commit

#### Notes about imports

- Imports should only be used at the top of the file (no function or scoped imports)
- Only modules should be imported

```python
# module1 contains very_long_module_name and function foo and variable var.
# very_long_module_name contains bar

# Yes:
from module1 import very_long_module_name as module2 # Casting to shorter name
import module1

module1.foo()
module1.var
module2.bar()

# No:
from module1.very_long_module_name import bar
from module1 import foo, var

foo()
var
bar()
```

### Other Style Guide Points

- Only imports, function, class, and constants declarations and the `if __name__ == '__main__'` should be in module scope
- Entry point to a script or program should be through the `main` function
- Add a trailing comma after elements of a list, if you wish to make/preserve each element on a separate line

## Typescript/React Style Guide

### Comments

#### Single Line Comments

Variable and function names should be descriptive enough to understand even without comments. Comments are needed to describe any complicated logic. You may use `//` or `/* */` for single line comments.

#### Function Comments

Function comments should follow the format shown below:
```typescript
/**
* @brief Adds two numbers together
*
* @param num1 - The first number to add.
* @param num2 - The second number to add.
* @return Returns the sum of the two numbers.
*/
function addNumbers(num1: number, num2: number): number {
return num1 + num2;
}
```

#### File Header Comments

- File comments are not required

### ****Naming and typing conventions****

- `variableNames` in camelCase
- `functionNames()` in camelCase
- `CONSTANT_NAME` in CAPITAL_SNAKE_CASE
- `file_names` in snake_case
- `ClassName` and `ComponentName` in PascalCase
Empty file added backend/__init__.py
Empty file.
Empty file added backend/api/__init__.py
Empty file.
33 changes: 33 additions & 0 deletions backend/api/lifespan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from contextlib import asynccontextmanager
from datetime import datetime
from fastapi import FastAPI
from sqlmodel import SQLModel, Session, select
from backend.data.data_models import MainCommand
from backend.data.engine import get_db
from backend.data.mock_data import commands, main_commands
from backend.utils.logging import logger_setup
from backend.utils.time import to_unix_time


def create_startup(session: Session) -> None:
logger_setup()
SQLModel.metadata.create_all(session.connection())
default_time = "2024-01-01T00:00:00"
default_datetime = datetime.strptime(default_time, "%Y-%m-%dT%H:%M:%S")
unix_time = to_unix_time(default_datetime)
# Setup the db with mock data
query = select(MainCommand).limit(1) # Check if the db is empty
result = session.exec(query).first()
if result is None:
session.add_all(main_commands())
session.commit()
session.add_all(commands(unix_time))
session.commit()


@asynccontextmanager
async def lifespan(_: FastAPI):
"""Lifecycle event for the FastAPI app."""
create_startup(get_db())
yield
print("Closing lifespan")
Empty file.
Loading
Loading