*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit f4ce5e2f authored by Sharma, Sukrit's avatar Sharma, Sukrit
Browse files

complete files

parent a9a2e27e
Branches
No related tags found
No related merge requests found
Showing
with 146 additions and 52 deletions
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class DetailConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'detail'
File added
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
from load_data.models import StandortTransition
from django_pandas.io import read_frame
import json
from django.http import JsonResponse
from edm_tuwien.decorators import group_required
@group_required('detail_group')
def detail(request):
if request.method == 'POST':
# Handle data received from frontend
campus = request.POST.get('campus')
address = request.POST.get('address')
# Process the data as needed
# Example: Query database based on selected campus and address
# Example: Return JsonResponse with relevant data
# Dummy response (replace with actual data retrieval logic)
response_data = {
'message': 'Data received successfully',
'selected_campus': campus,
'selected_address': address,
}
return JsonResponse(response_data)
# For GET requests, continue rendering the initial page
dataquery = StandortTransition.objects.all()
standort_data = read_frame(dataquery)
campuses = sorted(standort_data['Campus'].unique())
addresses = standort_data[['Campus', 'Adresse']].to_dict(orient='records')
addresses_json = json.dumps(addresses)
context = {
'campuses': campuses,
'addresses_json': addresses_json,
}
return render(request, 'detail.html', context)
......@@ -50,14 +50,14 @@ INSTALLED_APPS = [
"django.contrib.messages",
"django.contrib.staticfiles",
"bootstrap5",
"home.apps.HomeConfig",
"load_data.apps.LoadDataConfig",
"overview.apps.OverviewConfig",
"test_app.apps.TestAppConfig",
"map.apps.MapConfig",
"detail.apps.DetailConfig",
"crispy_forms",
"crispy_bootstrap5",
"home.apps.HomeConfig",
"detail.apps.DetailConfig",
"captcha"
]
......
This diff is collapsed.
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class HomeConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "home"
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
def home(request):
return render(request, "home.html")
# Create your views here.
# Generated by Django 4.2.11 on 2024-06-05 10:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("load_data", "0005_wienernetzteportaldata"),
]
operations = [
migrations.CreateModel(
name="FernwaermeRechnungenData",
fields=[
(
"Zaehlerpunkt",
models.CharField(max_length=255, primary_key=True, serialize=False),
),
("Address", models.CharField(max_length=255, null=True)),
("Messstelle", models.IntegerField(null=True)),
("Zeitraum", models.DateField(null=True)),
("Verbrauch_MWh", models.FloatField(null=True)),
("Kosten", models.FloatField(null=True)),
("Zahlungsperiode", models.CharField(max_length=1, null=True)),
("Campus", models.CharField(max_length=100, null=True)),
],
options={
"db_table": "fernwaerme_rechnungen",
"managed": False,
},
),
]
# Generated by Django 4.2.11 on 2024-07-04 08:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('load_data', '0006_fernwaermerechnungendata'),
]
operations = [
migrations.CreateModel(
name='GasWienerNetzteData',
fields=[
('Zählpunkt', models.CharField(max_length=255, primary_key=True, serialize=False)),
('Datum', models.DateField(null=True)),
('Von', models.CharField(max_length=255, null=True)),
('Bis', models.CharField(max_length=255, null=True)),
('Verbrauch', models.FloatField(null=True)),
],
options={
'db_table': 'data_gas',
'managed': False,
},
),
]
from django.test import TestCase
# Create your tests here.
import numpy as np
import pandas as pd
import datetime
from sklearn.linear_model import LinearRegression
import plotly.graph_objects as go
# Predict missing values for the current year
predicted_values = []
months = np.array([m for m in range(1, 13)]) # Numeric months
for month in month_names:
# Check if data for the latest year is missing for a specific month
if df_grouped[(df_grouped['Year'] == current_year) & (df_grouped['Monat'] == month_names[month])].empty:
# Get the data from previous years for this month
previous_years_data = df_grouped[
(df_grouped['Monat'] == month_names[month]) & (df_grouped['Year'] < current_year)]
if len(previous_years_data) > 1:
# Perform linear regression to predict the value for the missing month
X = np.array(previous_years_data['Year']).reshape(-1, 1)
y = np.array(previous_years_data['Verbrauch_kWh'])
model = LinearRegression()
model.fit(X, y)
predicted_value = model.predict([[current_year]])[0]
predicted_values.append(
{'Monat': month_names[month], 'Year': current_year, 'Verbrauch_kWh': predicted_value})
# Add predicted values as a new trace with black-bordered bubbles
if predicted_values:
df_predicted = pd.DataFrame(predicted_values)
fig.add_trace(go.Scatter(
x=df_predicted['Monat'],
y=df_predicted['Year'],
mode='markers',
marker=dict(
size=(df_predicted['Verbrauch_kWh'] * 30) / df_grouped['Verbrauch_kWh'].max(),
color=df_predicted['Verbrauch_kWh'],
colorscale='Jet',
opacity=0.8,
line=dict(width=2, color='black') # Black border for predicted values
),
text=df_predicted['Verbrauch_kWh'].astype(str).str.replace('.', ',', regex=True),
hovertemplate='%{text} GWh (Predicted)',
name="Predicted Verbrauch"
))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment