Skip to content

Commit

Permalink
Merge pull request EGCETSII#31 from Full-Tortuga/feature/telegramBot
Browse files Browse the repository at this point in the history
Feature/telegramBot-009
  • Loading branch information
anacatcam authored Jan 3, 2022
2 parents 283057b + 9927924 commit 9dbee3a
Show file tree
Hide file tree
Showing 21 changed files with 344 additions and 125 deletions.
2 changes: 1 addition & 1 deletion decide/base/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.5 on 2021-12-11 12:30
# Generated by Django 2.2.5 on 2021-12-11 16:57

import base.models
from django.db import migrations, models
Expand Down
2 changes: 1 addition & 1 deletion decide/census/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.5 on 2021-12-11 12:30
# Generated by Django 2.2.5 on 2021-12-11 16:57

from django.db import migrations, models

Expand Down
9 changes: 6 additions & 3 deletions decide/decide/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '^##ydkswfu0+=ofw0l#$kv^8n)0$i(qd&d&ol#p9!b$8*5%j1+'

#will change on production
TELEGRAM_TOKEN = '2111051748:AAH1R736I0_HsZEW6_22Tf0r-OqihtF5x88'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

Expand Down Expand Up @@ -151,7 +154,7 @@

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'
TIME_ZONE = 'Europe/Madrid'

USE_I18N = True

Expand All @@ -167,7 +170,7 @@

STATIC_URL = '/static/'

#temporary link to visualizer page for bots (until hosted)
#temporary link to visualizer page for bots
VISUALIZER_VIEW="https://decide-full-tortuga-2.herokuapp.com/visualizer/"

# number of bits for the key, all auths should use the same number of bits
Expand All @@ -191,4 +194,4 @@
vars()[k] = v


INSTALLED_APPS = INSTALLED_APPS + MODULES
INSTALLED_APPS = INSTALLED_APPS + MODULES
2 changes: 1 addition & 1 deletion decide/mixnet/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.5 on 2021-12-11 12:30
# Generated by Django 2.2.5 on 2021-12-11 16:57

from django.db import migrations, models
import django.db.models.deletion
Expand Down
2 changes: 1 addition & 1 deletion decide/store/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.5 on 2021-12-11 12:30
# Generated by Django 2.2.5 on 2021-12-11 16:57

import base.models
from django.db import migrations, models
Expand Down
12 changes: 11 additions & 1 deletion decide/visualizer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ def __str__(self):
return '{}'.format(self.auto_msg)

class Meta:
verbose_name = 'Telegram user'
verbose_name = 'Telegram user'



class Graphs(models.Model):
voting_id=models.BigIntegerField()
voting_type=models.CharField(max_length=30, default='V')
graphs_url=models.TextField(null=True, blank=True)

class Meta:
unique_together = ('voting_id', 'voting_type',)
52 changes: 52 additions & 0 deletions decide/visualizer/static/scripts/get_graphs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//ajax function to send graphs to backend
$(document).ready(async function(){
await new Promise(r => setTimeout(r, 1500));
var canvas_elements=document.getElementsByClassName("chartjs-render-monitor")
if (canvas_elements.length==2) {
$('#bar-chart').addClass(function(){
const csrf_cookie=getCookie('csrftoken');
$.ajax({
url: "graphs/",
type: "POST",
dataType:"json",
data:{
type:$('#vot_type').val(),
graphs:graphs_images(),
},
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", csrf_cookie)
},
failure: function(data){
console.log(error)
}
});
});
}
});

//retrieve canvas graphs as base64 encoded image
function graphs_images(){
var graphs=document.getElementsByClassName("chartjs-render-monitor");
var images=[];
for (var i=0; i< graphs.length; i++){
images.push(graphs[i].toDataURL());
}
return images
}

//function to retrieve csrf_cookie, copied from Django Docs
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// 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;
}
9 changes: 6 additions & 3 deletions decide/visualizer/static/visualizer.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
position: fixed;
width: 100%;
bottom : 0px;
margin-top: 10px;
height : 60px;
text-align: center;
vertical-align: middle;
padding-top: 0.5 rem;
padding-bottom: 0.5 rem;
background-color: rgba(var(--bs-secondary-rgb),var(--bs-bg-opacity));
color: #fff;
}

#start-tlg {
#start_tlg {
border: #79aec8;
border-radius: 12px;
font-size: 14px;
Expand All @@ -26,6 +26,9 @@
-o-border-radius: 12px;
}

#start-tlg:hover{
#start_tlg:hover{
background-color: #417690;
}
.chartjs-render-monitor{
margin: 77px 10px;
}
Loading

0 comments on commit 9dbee3a

Please sign in to comment.