Skip to content

Instantly share code, notes, and snippets.

<div class="" id="modal-form">
<h2>Login</h2>
<form method="POST" class="mx-auto" action="{% url 'login' %} ">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
{{ field }}
{% if field.help_text %}
<small class="form-text text-muted">{{ field.help_text|safe }}</small>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
</head>
{% load static %}
<section>
<small class="form-text text-muted">Choose a dataset</small>
<form action="{% url 'demographics' %}" class="" method="POST">
{% csrf_token %}
<div class="form-check form-check-inline">
// form dynamic request for charts
document.body.addEventListener( 'click', function (event) {
if( event.target.className === 'form-check-input dataset' ) {
const form = event.target.form;
const data = new FormData(form);
const request = new XMLHttpRequest();
request.open(form.method, form.action, true);
request.send(data);
}
from django.shortcuts import render
from django.template.loader import render_to_string
from django.views.decorators.http import require_http_methods
from django.http import JsonResponse
from .data_preparation import user_demographics, hashtag_demographics, creation_date_demographics, text_demographics, demographics_info
@require_http_methods(["GET", "POST"])
def demographics(request):
from .models import *
from nltk.tokenize import TweetTokenizer
from nltk.corpus import stopwords
import seaborn as sns
import time
def hashtag_demographics(route, label):
"""Return most-used hashtags."""
// form dynamic request for charts
document.body.addEventListener( 'click', function (event) {
if( event.target.className === 'form-check-input dataset' ) {
const form = event.target.form;
const data = new FormData(form);
const request = new XMLHttpRequest();
request.open(form.method, form.action, true);
request.send(data);
function get_time_config(label, data_labels, data_values) {
// configurations for the chart
return {
type: 'line',
data: {
labels: data_labels,
datasets: [{
label: 'counts',
data: data_values,
backgroundColor: Array(56).fill('rgba(255, 99, 132, 0.5)'),
def fonts(doc, granularity=False):
"""Extracts fonts and their usage in PDF documents.
:param doc: PDF document to iterate through
:type doc: <class 'fitz.fitz.Document'>
:param granularity: also use 'font', 'flags' and 'color' to discriminate text
:type granularity: bool
:rtype: [(font_size, count), (font_size, count}], dict
:return: most used fonts sorted by count, font style information
def font_tags(font_counts, styles):
"""Returns dictionary with font sizes as keys and tags as value.
:param font_counts: (font_size, count) for all fonts occuring in document
:type font_counts: list
:param styles: all styles found in the document
:type styles: dict
:rtype: dict
:return: all element tags based on font-sizes
def headers_para(doc, size_tag):
"""Scrapes headers & paragraphs from PDF and return texts with element tags.
:param doc: PDF document to iterate through
:type doc: <class 'fitz.fitz.Document'>
:param size_tag: textual element tags for each size
:type size_tag: dict
:rtype: list
:return: texts with pre-prended element tags