-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add analytics dashboard based on Flexmonster #1
Open
benkrikler
wants to merge
7
commits into
master
Choose a base branch
from
BenK_analytics-dashboard
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8ee28c8
Ignore vim swapfiles in gitignore
benkrikler 479707c
Add new app for dashboard
benkrikler bbbf049
Hook in the dashboard
benkrikler 61b12f6
Merge branch 'master' of github.com:THEPortatCERN/Hackathon2020-Pier8…
benkrikler 7c91a97
Sort the urls and paths for the flexmonster app. Also change the gith…
AlexxxH b2203cf
Add an initiate_survey module to allow users to send the surveys to a…
AlexxxH d3baf28
Merge branch 'master' into BenK_analytics-dashboard
benkrikler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ env | |
/humanitarian_feedback/mediafiles/ | ||
.env.* | ||
.env | ||
.*.sw[op] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class DashboardFlexmonsterConfig(AppConfig): | ||
name = 'dashboard_flexmonster' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
60 changes: 60 additions & 0 deletions
60
humanitarian_feedback/dashboard_flexmonster/templates/dashboard_with_pivot.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Dashboard with Flexmonster</title> | ||
<script src="https://cdn.flexmonster.com/flexmonster.js"></script> | ||
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> | ||
<link rel="stylesheet" href="https://cdn.flexmonster.com/demo.css"> | ||
</head> | ||
<body> | ||
<!-- TODO: Somehow I need to pass pivot_data url / function the survey_id parameter --> | ||
<div id="pivot-table-container" data-url="{% url 'pivot_data' survey_id=4%}"></div> | ||
<div id="pivot-chart-container"></div> | ||
<script type="text/javascript"> | ||
function processData(dataset) { | ||
var result = [] | ||
dataset = JSON.parse(dataset); | ||
dataset.forEach(item => result.push(item.fields)); | ||
return result; | ||
} | ||
$.ajax({ | ||
url: $("#pivot-table-container").attr("data-url"), | ||
dataType: 'json', | ||
success: function(data) { | ||
new Flexmonster({ | ||
container: "#pivot-table-container", | ||
componentFolder: "https://cdn.flexmonster.com/", | ||
width: "100%", | ||
height: 430, | ||
toolbar: true, | ||
report: { | ||
dataSource: { | ||
type: "json", | ||
data: processData(data) | ||
}, | ||
slice: {} | ||
} | ||
}); | ||
new Flexmonster({ | ||
container: "#pivot-chart-container", | ||
componentFolder: "https://cdn.flexmonster.com/", | ||
width: "100%", | ||
height: 430, | ||
//toolbar: true, | ||
report: { | ||
dataSource: { | ||
type: "json", | ||
data: processData(data) | ||
}, | ||
slice: {}, | ||
"options": { | ||
"viewType": "charts", | ||
"chart": { | ||
"type": "pie" | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.conf.urls import url | ||
from django.urls import path | ||
from . import views | ||
|
||
urlpatterns = [path('', views.dashboard_with_pivot, name='dashboard_with_pivot'), | ||
path('data/', views.pivot_data, name='pivot_data', ), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.http import JsonResponse | ||
from django.shortcuts import render | ||
#from dashboard_flexmonster.models import Order | ||
from django.core import serializers | ||
|
||
|
||
from sms_auto_surveys.models import Survey | ||
|
||
|
||
def dashboard_with_pivot(request, survey_id): | ||
return render(request, 'dashboard_with_pivot.html', {}) | ||
|
||
|
||
def pivot_data(request, survey_id): | ||
print("BEK", survey_id) | ||
# DONE: BEK change this line to get data from our survey models | ||
# dataset = Order.objects.all() | ||
|
||
# TODO: add the survey_id as a parameter of the request | ||
#survey_id = 4 | ||
survey = Survey.objects.get(id=survey_id) | ||
dataset = [response for response in survey.responses] | ||
|
||
data = serializers.serialize('json', dataset) | ||
return JsonResponse(data, safe=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
# Local Apps | ||
'users', | ||
'sms_auto_surveys', | ||
'dashboard_flexmonster', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexxxH I think this is the line I need to fix now - somehow I need to pass
survey_id
through and doing it here works, but is obviously hard-coded the survey ID - is there way to access this parameter at this point or some alternative approach I should use?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think I might have understood what I was missing (or at least one way to fix this): I should pass
survey_id
as a parameter to the overall template via this line: https://github.com/THEPortatCERN/Hackathon2020-Pier84/pull/1/files#diff-89918cd6e497bfe3ee6e33b23d2ef640R11