Skip to content

Commit

Permalink
Refactor repository (#176)
Browse files Browse the repository at this point in the history
* Begin refactor

* Fix a few imports

* Fix tests

* Fix test (1)

* Move scripts

* Fix import

* Fix import (2) >:(

* Update README
  • Loading branch information
joshuaRiefman authored Apr 6, 2024
1 parent 63d8fca commit 80025cc
Show file tree
Hide file tree
Showing 53 changed files with 73 additions and 165 deletions.
11 changes: 3 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ dmypy.json
# VS Code settings
.vscode

# Numpy data files
data/route/*.npz
data/weather/*.npz

# HTML Output files
examples/*.html
*.html
Expand All @@ -145,10 +141,6 @@ simulation/examples/cProfile
# Docs
docs/UBC Solar - Simulation.pdf

# Config files
simulation/config/settings_ASC.json
simulation/config/settings_FSGP.json

# Data Images
data/images/*.png

Expand All @@ -159,6 +151,9 @@ data/images/*.png
.idea
/simulation/examples/.env

# Env Files
*.env

# OS Stuff
.DS_Store

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ Or, you can run the script directly. Before running the following commands make
#### Unix

```bash
python3 simulation/run_simulation.py
python3 simulation/cmd/run_simulation.py
```
#### Windows

```bash
python .\simulation\run_simulation.py
python .\simulation\cmd\run_simulation.py
```

### Arguments
Expand All @@ -113,12 +113,12 @@ You can view a list of valid arguments and settings that Simulation can accept w
#### Unix

```bash
python3 simulation/run_simulation.py -help
python3 simulation/cmd/run_simulation.py -help
```
#### Windows

```bash
python .\simulation\run_simulation.py -help
python .\simulation\cmd\run_simulation.py -help
```

### Testing
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ enabled = true
packages = ["simulation"]

[project.scripts]
run_simulation = "simulation.run_simulation:main"
simulation_health_check = "simulation.run_simulation:_health_check"
build_simulation = "simulation.run_simulation:_execute_build_script"
run_simulation = "simulation.cmd.run_simulation:main"
simulation_health_check = "simulation.cmd.run_simulation:_health_check"
build_simulation = "simulation.cmd.run_simulation:_execute_build_script"

[[tool.setuptools-rust.ext-modules]]
# Private Rust extension module to be nested into the Python package
Expand Down
3 changes: 0 additions & 3 deletions simulation/.idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions simulation/.idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

4 changes: 0 additions & 4 deletions simulation/.idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions simulation/.idea/modules.xml

This file was deleted.

15 changes: 0 additions & 15 deletions simulation/.idea/simulation.iml

This file was deleted.

6 changes: 0 additions & 6 deletions simulation/.idea/vcs.xml

This file was deleted.

30 changes: 15 additions & 15 deletions simulation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
from simulation.common import BatteryEmptyError
from simulation.common import PrematureDataRecoveryError

from simulation.arrays import BaseArray
from simulation.battery import BaseBattery
from simulation.lvs import BaseLVS
from simulation.motor import BaseMotor
from simulation.regen import BaseRegen
from simulation.model.car.arrays import BaseArray
from simulation.model.car.battery import BaseBattery
from simulation.model.car.lvs import BaseLVS
from simulation.model.car.motor import BaseMotor
from simulation.model.car.regen import BaseRegen

from simulation.arrays import BasicArray
from simulation.battery import BasicBattery
from simulation.lvs import BasicLVS
from simulation.motor import BasicMotor
from simulation.regen import BasicRegen
from simulation.model.car.arrays import BasicArray
from simulation.model.car.battery import BasicBattery
from simulation.model.car.lvs import BasicLVS
from simulation.model.car.motor import BasicMotor
from simulation.model.car.regen import BasicRegen

from simulation.environment.GIS import GIS
from simulation.environment.SolarCalculations import SolarCalculations
from simulation.environment.WeatherForecasts import WeatherForecasts
from simulation.model.environment.GIS import GIS
from simulation.model.environment.SolarCalculations import SolarCalculations
from simulation.model.environment.WeatherForecasts import WeatherForecasts

from simulation.library import Libraries
from simulation.utils.Plotting import Plotting

from simulation.main import Simulation
from simulation.main import Model
from simulation.model.Simulation import Simulation
from simulation.model.Model import Model
2 changes: 0 additions & 2 deletions simulation/arrays/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions simulation/battery/__init__.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from simulation.cache.weather import weather_directory
from simulation.common import ASC, FSGP, constants, BrightSide, helpers


# load API keys from environment variables
load_dotenv()

Expand Down
9 changes: 5 additions & 4 deletions simulation/data/controller.py → simulation/cmd/push_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import googleapiclient.discovery
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from upload import Uploader
from download import Downloader
from assemble import Assembler
from simulation.data.upload import Uploader
from simulation.data.download import Downloader
from simulation.data.assemble import Assembler
from simulation.data import data_directory
from collections import OrderedDict
from pathlib import Path

Expand All @@ -24,7 +25,7 @@
class Controller:
def __init__(self, results_directory: str):
# Get the data directory and config
self.data_directory = pathlib.Path(__file__).parent.resolve()
self.data_directory = data_directory
with open(self.data_directory / "network.toml", 'rb') as config_file:
config = tomllib.load(config_file)
self.scopes = config['settings']['SCOPES']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import csv

from simulation.main import Simulation, SimulationReturnType
from simulation.model.Simulation import Simulation, SimulationReturnType
from simulation.utils.InputBounds import InputBounds
from simulation.config import config_directory
from simulation.utils.SimulationBuilder import SimulationBuilder
Expand Down
2 changes: 1 addition & 1 deletion simulation/data/Evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd

from simulation.optimization.genetic import GeneticOptimization
from simulation.main import Simulation
from simulation.model.Simulation import Simulation


class Evolution:
Expand Down
3 changes: 3 additions & 0 deletions simulation/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
from simulation.data.download import Downloader
from simulation.data.assemble import Assembler
from simulation.data.upload import Uploader
import pathlib

data_directory = pathlib.Path(__file__).parent.resolve()
2 changes: 1 addition & 1 deletion simulation/data/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pathlib
import numpy as np
import pandas as pd
from simulation.main import Simulation
from simulation.model.Simulation import Simulation
from simulation.data.Evolution import Evolution
from simulation.optimization.genetic import GeneticOptimization

Expand Down
3 changes: 0 additions & 3 deletions simulation/environment/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions simulation/lvs/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions simulation/main/__init__.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import simulation
import functools
import logging
import core
import os
import core
import numpy as np

from typing import Union
Expand All @@ -13,6 +13,7 @@
from simulation.common.exceptions import LibrariesNotFound
from simulation.utils.Plotting import GraphPage


def simulation_property(func):
"""
Expand Down
Empty file added simulation/model/__init__.py
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions simulation/model/car/arrays/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from simulation.model.car.arrays.base_array import BaseArray
from simulation.model.car.arrays.basic_array import BasicArray
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from simulation.arrays.base_array import BaseArray
from simulation.model.car.arrays.base_array import BaseArray
from simulation.common import DayBreak


Expand Down
2 changes: 2 additions & 0 deletions simulation/model/car/battery/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from simulation.model.car.battery.base_battery import BaseBattery
from simulation.model.car.battery.basic_battery import BasicBattery
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from simulation.common import BatteryEmptyError
from simulation.common import Storage


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from simulation.battery.base_battery import BaseBattery
from simulation.model.car.battery.base_battery import BaseBattery
from simulation.common import DayBreak, DayBreakEquations as equations


Expand Down
2 changes: 2 additions & 0 deletions simulation/model/car/lvs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from simulation.model.car.lvs.base_lvs import BaseLVS
from simulation.model.car.lvs.basic_lvs import BasicLVS
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from simulation.lvs.base_lvs import BaseLVS
from simulation.model.car.lvs.base_lvs import BaseLVS
from simulation.common import DayBreak


Expand Down
2 changes: 2 additions & 0 deletions simulation/model/car/motor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from simulation.model.car.motor.base_motor import BaseMotor
from simulation.model.car.motor.basic_motor import BasicMotor
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math
import numpy as np

from simulation.motor.base_motor import BaseMotor
from simulation.model.car.motor.base_motor import BaseMotor
from simulation.common import DayBreak, constants, DayBreakEquations


Expand Down
2 changes: 2 additions & 0 deletions simulation/model/car/regen/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from simulation.model.car.regen.base_regen import BaseRegen
from simulation.model.car.regen.basic_regen import BasicRegen
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from simulation.regen import BaseRegen
from simulation.model.car.regen import BaseRegen
import numpy as np


Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import datetime
import os
import json
import logging
import math
import numpy as np
import sys

from simulation.cache.route import route_directory
from simulation.common import helpers, ASC, FSGP, BrightSide
from simulation.config import config_directory
from simulation.common import helpers
from dotenv import load_dotenv
from tqdm import tqdm
from sklearn.neighbors import BallTree
from math import radians
from xml.dom import minidom
import core

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
A class to extract local and path weather predictions such as wind_speed,
wind_direction, cloud_cover and weather type
"""
import json
import numpy as np
import os
import requests
import logging

from simulation.cache.weather import weather_directory
Expand Down
3 changes: 3 additions & 0 deletions simulation/model/environment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from simulation.model.environment.GIS import GIS
from simulation.model.environment.SolarCalculations import SolarCalculations
from simulation.model.environment.WeatherForecasts import WeatherForecasts
2 changes: 0 additions & 2 deletions simulation/motor/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion simulation/optimization/genetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from simulation.common.helpers import denormalize, normalize, rescale
from simulation.common.noise import Noise
from simulation.utils import InputBounds
from simulation.main import Simulation, SimulationReturnType
from simulation.model.Simulation import Simulation, SimulationReturnType

"""
Expand Down
2 changes: 0 additions & 2 deletions simulation/regen/__init__.py

This file was deleted.

5 changes: 3 additions & 2 deletions simulation/utils/MapPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from PIL import Image
from dotenv import load_dotenv
from io import BytesIO
from simulation.environment import GIS
from simulation.model.environment.GIS import GIS


BACKGROUND_IMAGE_PATH = './data/images/'
BACKGROUND_COORDINATE_DATA_NAME = 'coordinates.json'
Expand Down Expand Up @@ -94,6 +95,6 @@ def plotPath(self, waypoints):
])

locationSystem = GIS(api_key=google_api_key, origin_coord=origin_coord, dest_coord=dest_coord, waypoints=waypoints,
race_type="FSGP", force_update=True)
race_type="FSGP")
map = MapPlot(locationSystem.path, locationSystem.calculate_path_min_max())
map.plotPath(locationSystem.waypoints)
Loading

0 comments on commit 80025cc

Please sign in to comment.