Skip to content

Commit

Permalink
Template changes() (#8)
Browse files Browse the repository at this point in the history
* Removed redis source code

* Removing extra files and try to Give appropriate naming of function and folders

* trying to resolve conflict

* templet changes()

* adding SMAVG and WMAVG
  • Loading branch information
agl29 authored and Rishabh Agrahari committed Mar 26, 2018
1 parent 5677381 commit c55d59d
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 67 deletions.
2 changes: 2 additions & 0 deletions celery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
celery -A website worker -c1 -l info
celery -A website beat -l info
29 changes: 16 additions & 13 deletions server/static/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
let data;
$('#ddd').on('click', function() {
var gape = {
from: $("#from").val(),
to: $("#to").val(),
"from": $("#from").val(),
"to": $("#to").val(),
};
console.log("adsfadsfdff");
console.log(gape);
console.log(gape.from);
// console.log(gape);
// console.log(gape.from);
var csrftoken = getCookie('csrftoken');
$.ajaxSetup({
beforeSend: function(xhr, settings) {
Expand All @@ -24,10 +23,11 @@ $('#ddd').on('click', function() {
});
});

const fun = function(data){
console.log('asdgf',data);
const fun = function(da){
console.log('asdgf',da);
console.log("ooooooooooooooooooooooooooooooo");
let load = data;
let load = da;
console.log(load.Load);
// let datee = (parseInt(tarikh[8]+tarikh[9]) + i).toString() + '-' + tarikh[5]+tarikh[6] +'-'+tarikh[0]+tarikh[1]+tarikh[2]+tarikh[3];
var chart = c3.generate({
bindto: '#d',
Expand All @@ -46,19 +46,22 @@ const fun = function(data){
x: {
label:{
text: 'Time',
position:'outer-center',
position:'outer-right',
},
type: 'timeseries',
tick:{
format:'%H:%M'
}
}
},
zoom: {
enabled:true,
rescale:true,
extent: [1, 100],
point: {
show: false
},
// zoom: {
// enabled:true,
// rescale:true,
// extent: [1, 100],
// },
grid: {
x: {
show: true,
Expand Down
137 changes: 137 additions & 0 deletions server/static/main1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
$('#dddd').on('click', function() {
var gap = {
"fc": $("#fc").val(),
// to: $("#to").val(),
};
console.log("adsfadsfdff");
console.log(gap);
console.log(gap.fc);
var csrftoken = getCookie('csrftoken');
$.ajaxSetup({
beforeSend: function(xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
});
$.ajax({
type: 'POST',
url: '/show_forecasted_smavg_data/',
data: gap,
success: function(x){
console.log(x);
fun1(x);
},
});
});

const fun1 = function(data){
console.log('asdgf',data);
console.log("ooooooooooooooooooooooooooooooo");
let load = data;
console.log(load.forecasted_Load);
// let datee = (parseInt(tarikh[8]+tarikh[9]) + i).toString() + '-' + tarikh[5]+tarikh[6] +'-'+tarikh[0]+tarikh[1]+tarikh[2]+tarikh[3];
var chart = c3.generate({
bindto: '#Forecasting',
data: {
x: 'x',
xFormat:'%H:%M',
columns: load.forecasted_Load,
},
axis: {
y: {
label:{
text:'POWER IN MW',
position: 'outer-middle',
},
},
x: {
label:{
text: 'Time',
position:'outer-right',
},
type: 'timeseries',
tick:{
format:'%H:%M'
}
}
},
point: {
show: false
},
// zoom: {
// enabled:true,
// rescale:true,
// extent: [1, 100],
// },
grid: {
x: {
show: true,
},
y: {
show: true,
},
},
});
};

function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

// $(document).ready(function(){
// $('#kp').on('click', function(){
// console.log("ooooooooooooooooooooooooooooooo");
// let load = data;
// // let datee = (parseInt(tarikh[8]+tarikh[9]) + i).toString() + '-' + tarikh[5]+tarikh[6] +'-'+tarikh[0]+tarikh[1]+tarikh[2]+tarikh[3];
// var chart = c3.generate({
// bindto: '#d',
// data: {
// x: 'x',
// xFormat:'%H:%M',
// columns: load.Load,
// },
// axis: {
// y: {
// label:{
// text:'POWER IN MW',
// position: 'outer-middle',
// },
// },
// x: {
// label:{
// text: 'Time',
// position:'outer-center',
// },
// type: 'timeseries',
// tick:{
// format:'%H:%M'
// }
// }
// },
// zoom: {
// enabled:true,
// rescale:true,
// extent: [1, 100],
// },
// grid: {
// x: {
// show: true,
// },
// y: {
// show: true,
// },
// },
// });
// });
// });
22 changes: 9 additions & 13 deletions server/swag/load_data.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@

import sys,os
djangoproject_home="website"
sys.path.append(djangoproject_home)
os.environ['DJANGO_SETTINGS_MODULE'] = 'website.settings'
from .models import CSV
import csv,datetime
for i in range(10,11):
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')
django.setup()
from swag.models import CSV
import csv, datetime

for i in range(22,24):
a = 1+i;
print(a);
link = "static/SLDC_Data/2018/02/"+str(a).zfill(2)+"-02-2018.csv"
link = "static/SLDC_Data/2018/03/"+str(a).zfill(2)+"-03-2018.csv"
dataReader = csv.reader(open(link), delimiter=',', quotechar='"')
for row in dataReader:
data = CSV()
data.timestamp = row[0]
data.load_value = row[1]
data.date = datetime.date(2018,2,a)
data.save()
data = CSV.objects.create(timestamp = row[0], load_value = row[1], date = datetime.date(2018,3,a))
11 changes: 9 additions & 2 deletions server/swag/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from .models import CSV
import csv,datetime

# from .views import forecasted_plot

# @periodic_task(run_every=(crontab(minute='*/1')), name="update_database", ignore_result=True)

size=1
Expand Down Expand Up @@ -62,17 +64,20 @@ def reload_task():
time, delhi = tr.findChildren('font')[:2]
t = (time.text).split(':')
TimE = datetime.time(int(t[0]),int(t[1]))
writer.writerow([str(TimE), delhi.text,randint(2000,2800)])
writer.writerow([str(TimE), delhi.text, randint(2000,2800)])
size_reduction = 0
if(str(TimE) != '23:55:00'):
print('............................................')
x = str(TimE)
size_reduction = 0
while(x != '23:55:00'):
tym = x.split(':')
Time = datetime.time(int(tym[0]),int(tym[1]))
TIME = (datetime.datetime.combine(datetime.date(1,1,1),Time)+timedelta(minutes=5)).time()
# print((datetime.datetime.combine(datetime.date(1,1,1),Time)+timedelta(minutes=5)).time())
writer.writerow([TIME,'None',randint(3000,3600)])
x = str(TIME)
size_reduction = size_reduction+1
except Exception as e:
print(e)

Expand All @@ -85,16 +90,18 @@ def reload_task():
print("global k baad",size)
# if(len(rows) > size):
print(len(rows))
print(size_reduction)
for row in rows[size:len(rows)+1]:
print("inside 2")
data = CSV()
if(row[1]=='None'):
break
print('row[0]',row[0])
data.timestamp = row[0]
data.load_value = row[1]
data.date = datetime.date(datetime.date.today().year,datetime.date.today().month,datetime.date.today().day)
data.save()
size = len(rows)
size = len(rows)-size_reduction
print("final wali........end",size)
print("update_done...............yupppp")

Expand Down
86 changes: 83 additions & 3 deletions server/swag/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ def home_page(request):
'Month': str(month).zfill(2),
'Year': year})



def graph_plot(request):
print("insde graph_plot");
if request.method == 'POST':
print(request.POST)
# query_results = CSV.objects.filter(date = request.POST['from'])
a = request.POST['from']
b = request.POST['to']
Expand Down Expand Up @@ -57,7 +56,7 @@ def graph_plot(request):

else:
last = None
print ('sadf',last)
# print ('sadf',last)
cont = {
# "query_results":query_results,
'Load':last,
Expand All @@ -68,3 +67,84 @@ def graph_plot(request):
}

return HttpResponse(json.dumps(cont),content_type='application/json')


def forecasted_plot(request):
print("insde forecasted_plot");
if request.method == 'POST':
# query_results = CSV.objects.filter(date = request.POST['from'])
# if 'fc' in request.POST:
# qq = request.POST['fc']
# else:
# qq = False
# a = request.POST.get('fc', False)
print(request.POST)
qq = request.POST['fc']
p=5
print(qq)
print("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq")
ans = qq.split('-')
# bns = b.split('-')
aa = datetime.date(int(ans[0]),int(ans[1]),int(ans[2]))
# bb = datetime.date(int(bns[0]),int(bns[1]),int(bns[2])-p)
query_results = []
last = []
l = []
t = ['x']
for i in range(p+1):
print(i ,"ayushJXHDKJHFKJDBH")
query_results.append(CSV.objects.filter(date = aa-timedelta(days=i)))
q = [str(aa-timedelta(days=i))]
for x in query_results[i]:
q.append(x.load_value)
last.append(q)
# print(len(q))
# print(last[1])
# print(q)
weights = [0.4, 0.2, 0.15, 0.15, 0.1]
weights_load = ['forecasted with wmavg']
simple_load = ['forecasted with smavg']
for i in range(1,289):
init = 0
init1 = 0
no_of_data = 0
total_weight = 0
for j in range(1,p+1):
try:
# print(j)
init += last[j][i]
# print(weights[j-1],last[j][i])
init1 += weights[j-1]*last[j][i]
no_of_data = no_of_data+1
total_weight = total_weight+weights[j-1]
except Exception as e:
print(e)
# print(last[j][i])
# print()
# print(total_weight,no_of_data)
weights_load.append("%.2f" % (init1/total_weight))
simple_load.append("%.2f" % (init/no_of_data))
# print(w)
l.append(simple_load)
l.append(weights_load)
l.append(last[0])
# print(query_results)
for x in query_results[p]:
hour = x.timestamp.hour
minutes = x.timestamp.minute
t.append(str(hour)+':'+str(minutes))
l.insert(0,t)

else:
l = None
# print ('sadf',w)
cont = {
# "query_results":query_results,
'forecasted_Load':l,
# 'Tarikh':a,
# 'T':mark_safe(t),
# 'Load': [x.load_value for x in query_results],
# 'Time': [x.timestamp for x in query_results],
}

return HttpResponse(json.dumps(cont),content_type='application/json')
Loading

0 comments on commit c55d59d

Please sign in to comment.