Skip to content

Commit

Permalink
Add update valuetypes command
Browse files Browse the repository at this point in the history
Bring a list of value type to edit the DB more easily
  • Loading branch information
Bachibouzouk committed Oct 29, 2022
1 parent 7922d7d commit 850b593
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/projects/management/commands/update_valuetype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.core.management.base import BaseCommand, CommandError
import pandas as pd
from projects.models import *


class Command(BaseCommand):
help = "Update the valuetype objects from /static/valuetypes_list.csv"

def add_arguments(self, parser):
parser.add_argument(
"--update", action="store_true", help="Update existing assets"
)

def handle(self, *args, **options):

update_valuetypes = options["update"]

df = pd.read_csv("static/valuetypes_list.csv")
valuetypes = df.to_dict(orient="records")
for vt_params in valuetypes:
qs = ValueType.objects.filter(type=vt_params["type"])

if qs.exists() is False:
new_valuetype = ValueType(**vt_params)
new_valuetype.save()
else:
if update_valuetypes is True:
qs.update(**vt_params)
33 changes: 33 additions & 0 deletions app/static/valuetypes_list.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
type,unit
duration,year
annuity_factor,factor
discount,factor
tax,factor
crf,factor
crate,factor of total capacity (kWh)
age_installed,year
soc_max,factor
soc_min,factor
capex_fix,currency
opex_var,currency/unit/year
efficiency,factor
installed_capacity,unit
lifetime,year
maximum_capacity,kW
energy_price,currency/kWh
feedin_tariff,currency/kWh
optimize_cap,bool
peak_demand_pricing,currency/kW
peak_demand_pricing_period,"times per year (1,2,3,4,6,12)"
renewable_share,factor
capex_var,currency/unit
opex_fix,currency/year
specific_costs_om,currency/year
input_timeseries,kWh
evaluated_period,days
renewable_asset,bool
thermal_loss_rate,factor
efficiency_multiple,factor
beta,factor
fixed_thermal_losses_relative,factor
fixed_thermal_losses_absolute,kWh

0 comments on commit 850b593

Please sign in to comment.