Skip to content

Commit

Permalink
Merge pull request #77 from H-Huang/develop
Browse files Browse the repository at this point in the history
Final PR of our project
  • Loading branch information
H-Huang authored Jun 7, 2017
2 parents 0cdfe4b + 8d0edec commit bab51f1
Show file tree
Hide file tree
Showing 25 changed files with 1,763 additions and 214 deletions.
33 changes: 33 additions & 0 deletions LL1_Academy/management/commands/populate.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
from django.core.management.base import BaseCommand, CommandError
from LL1_Academy.tools import MassGrammarGenerator
from LL1_Academy.models import Grammar
import os
import sys
import time
from django.core.management import call_command


class Command(BaseCommand):
help = 'This command will add grammars to the database, starting from <num> grammars and gradually filtering them down to a valid set (which may be much less than <num>)'

def add_arguments(self, parser):
parser.add_argument('num', type=int)
parser.add_argument('--reset',
action='store_true',
dest='reset_db',
default=False,
help='Clear database and repopulate it',
)
parser.add_argument('--silent',
action='store_true',
dest='silent',
default=False,
help='Will not show the actual grammars being generated',
)


def handle(self, *args, **options):
if (options['reset_db']):
call_command('cleardatabase')

print("Grammar objects initially in database: {}".format(Grammar.objects.count()))
#Number of randomly generated grammars
num = options['num']

Expand All @@ -21,8 +42,20 @@ def handle(self, *args, **options):
nonTerminals = ['A','B','C','D']
terminals = ['x','y','z','w']



if options['silent']:
sys.stdout = open(os.devnull, "w")

for n in nVariables:
start_time = time.time()
mg = MassGrammarGenerator.MassGrammarGenerator(n)
mg.run(num,nonTerminals[:n],terminals)
print("{}Variables: {} seconds---".format(n,(time.time() - start_time)))

if options['silent']:
sys.stdout = sys.__stdout__

print("Grammar objects finally in database: {}".format(Grammar.objects.count()))


11 changes: 8 additions & 3 deletions LL1_Academy/templates/LL1_Academy/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
<head>
<title>LL(1) Academy - {% block title %}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="LL(1) Academy" />
<meta property="og:image" content="https://i.imgur.com/cZ0wjGw.png" />
<meta property="og:description" content="Better your understanding of LL(1) Grammars." />
<meta charset="UTF-8">
<meta http-equiv="Content-Language" content="en">
<meta property="fb:app_id" content="814858888663958">
<meta property="og:url" content="https://sheltered-sands-11346.herokuapp.com/">
<meta property="og:title" content="LL(1) Academy">
<meta property="og:image" content="https://i.imgur.com/cZ0wjGw.png">
<meta property="og:description" content="Better your understanding of LL(1) Grammars by visiting this tutorial website and doing practice problems.">
<link rel="icon" href="/static/img/LL1-logo.ico" type="image/jpg" sizes="32x32">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/css/foundation.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pretty-checkbox/2.2.1/pretty.min.css"/>
<link rel="stylesheet" href="{% static 'css/main.css' %}" />
<link rel="stylesheet" href="https://cdn.iconmonstr.com/1.2.0/css/iconmonstr-iconic-font.min.css">
<link rel="stylesheet" type="text/css" href="{% static 'sweetalert/sweetalert.css' %}">
Expand Down
14 changes: 10 additions & 4 deletions LL1_Academy/templates/LL1_Academy/_navbarPages.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@
<div id="navbarUser">
{% if user.is_authenticated %}
<p style="color:white;font-size:20px;">Welcome back <a href="/profile" style="font-weight: bold;text-transform: capitalize;">{{ user.username }}</a>! <a href="/profile"><img src="{{user.socialaccount_set.all.0.get_avatar_url}}" class="img-circle"></a></p>
{% if request.path != '/learn' %}
<a href="/learn"><button class="button indexButtons navbarButton">Learn</button></a>
{% if request.path != '/tutorial' %}
<a href="/tutorial"><button class="button indexButtons navbarButton">Tutorial</button></a>
{% endif %}
{% if request.path != '/practice' %}
<a href="/practice"><button class="button indexButtons navbarButton">Practice</button></a>
{% endif %}
<a href="/accounts/logout" style="justify-content:center;"><button class="button indexButtons navbarButton">Logout</button></a>
{% else %}
{% if request.path != '/learn' %}
<a href="/learn"><button class="button indexButtons navbarButton">Learn</button></a>
{% if request.path != '/tutorial' %}
<a href="/tutorial"><button class="button indexButtons navbarButton">Tutorial</button></a>
{% endif %}
{% if request.path != '/practice' %}
<a href="/practice"><button class="button indexButtons navbarButton">Practice</button></a>
{% endif %}
<a href="/index"><button class="button indexButtons navbarButton">Login</button></a>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions LL1_Academy/templates/LL1_Academy/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h3 style="text-align:center;font-weight:bold;"> About the Project </h3>
<h3 style="text-align:center;font-weight:bold;"> Meet the Team </h3>
<div class="row bioRow">
<div class="large-6 columns bioCol">
<img src="{% static 'img/filler.png' %}">
<img src="{% static 'img/julien.jpg' %}">
<a href="https://www.linkedin.com/in/jbrundrett/"><h5>Julien Brundrett</h5></a>
<p>4th Year, B.S. Computer Science</p>
</div>
Expand All @@ -40,7 +40,7 @@ <h3 style="text-align:center;font-weight:bold;"> Meet the Team </h3>
</div>
<div class="row bioRow">
<div class="large-6 columns bioCol">
<img src="{% static 'img/vivian.JPG' %}">
<img src="{% static 'img/vivian.jpg' %}">
<a href="https://www.linkedin.com/in/vivian-ni-zhang/"><h5>Vivian Ni Zhang</h5></a>
<p>4th Year, B.S. Computer Science</p>
</div>
Expand Down
23 changes: 16 additions & 7 deletions LL1_Academy/templates/LL1_Academy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,36 @@
<h1 id="siteTitle">LL(1) Academy</h1>
<div id="loginActions">
{% if user.is_authenticated %}
<p style="color:white;font-size:30px;">Welcome back <a href="profile" style="font-weight: bold;text-transform: capitalize;">{{ user.username }}</a>!</p>
<a href="accounts/logout"><button class="button indexButtons">Logout</button></a>
<p style="display:inline;color: white;margin-left:10px; margin-right:10px;">or</p>
<a href="/learn"><button class="button indexButtons">Start Learning</button></a>
{% if messages %}
{% for message in messages %}
<p class="message" style="color:white;font-size:15px; display: none;">
{{ message }}
</p>
{% endfor %}
{% endif %} <p style="color:white;font-size:30px;">Welcome back <a href="profile" style="font-weight: bold;text-transform: capitalize;">{{ user.username }}</a>!</p>
<div style="margin-bottom:20px;">
<div class="loginOption" style="margin:0 15px 15px 0;"><a href="/tutorial"><button class="button indexButtons" style="width:125px;">Tutorial</button></a></div>
<div class="loginOption"><a href="/practice"><button class="button indexButtons" style="width:125px;">Practice</button></a></div>
</div>
<a href="accounts/logout"class="footerLinks index" style="font-size:20px;">or logout</a>

{% else %}
{% block login_error %}
{% endblock %}
{% if messages %}
{% for message in messages %}
<p class="message" style="color:white;font-size:15px;">
{{ message }}
{{ message }}
</p>
{% endfor %}
{% endif %}
{% load socialaccount %}
{% providers_media_js %}
<div id="socialMediaLogin" style="margin-bottom:20px;">
<div style="margin-bottom:20px;">
<div class="loginOption" style="margin:0 15px 15px 0;"><a href="{% provider_login_url "facebook" method="js_sdk" %}"><button class="button indexButtons" style="width:225px;">Login with Facebook</button></a></div>
<div class="loginOption"><a href="{% provider_login_url "google" method="oauth2" %}"><button class="button indexButtons" style="width:225px;">Login with Google</button></a></div>
</div>
<a href="/learn" class="footerLinks index" style="font-size:20px;">or learn without an account</a>
<a href="/tutorial" class="footerLinks index" style="font-size:20px;">or begin without an account</a>
{% endif %}
</div>
<div id="indexFooter">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% load static %}

{% block title %}Learning{% endblock %}
{% block title %}Practice{% endblock %}

{% block templates %}
{% verbatim %}
Expand All @@ -16,21 +16,27 @@
{{/if}}
<form id="question-input" onsubmit="return false;">
{{#if symbol}}
<input type="text" id="question-answer" placeholder="example: x,y,z" required>

<!-- <input type="text" id="question-answer" placeholder="example: x,y,z" required> -->
{{#each terminals}}
<div class="pretty info smooth">
<input type="checkbox" name="question-check" id="{{this}}-check" value="{{this}}">
<label for="{{this}}-check"><i class="im im-check-mark"></i>{{this}}</label>
</div>
{{/each}}
{{else}}
<input type="radio" name="ll1" value="True" id="input1" style="display:inline;" required> True
<input type="radio" name="ll1" value="False" id="input2" style="display:inline;margin-left:10px;"> False
<div class="pretty circle info">
<input type="radio" name="ll1" value="True" id="input1" style="display:inline;">
<label><i class="im im-radio-button-circle"></i> True</label>
</div>
<div class="pretty circle info">
<input type="radio" name="ll1" value="False" id="input2" style="display:inline; margin-left:10px;">
<label><i class="im im-radio-button-circle" ></i> False</label>
</div>
{{/if}}
<div class="feedback"></div>
<div id="buttons-container">
{{#if opt}}
<button class="button" type="button" id="opt-char">{{opt}}</button>
{{/if}}
<div id="right-buttons" style="float: right;">
<button type="button" class="button" id="giveup">Give Up</button>
<button type="submit" class="button" >Submit</button>
</div>
</div>
</form>
</div>
Expand All @@ -51,17 +57,18 @@
{{#each non_terminals}}
<tr>
<td>{{this}}</td>
{{printParseTableCells}}
{{printParseTableCells this}}
</tr>
{{/each}}
</table>

<form id="question-input" onsubmit="return false;">
<div class="feedback"></div>
<div id="buttons-container">
{{#if opt}}
<div id="production-options"> </div>
<!-- {{#if opt}}
<button class="button" type="button" id="opt-char-pt">{{opt}}</button>
{{/if}}
{{/if}} -->
<div id="right-buttons" style="float: right;">
<button type="button" class="button" id="giveup">Give Up</button>
<button type="submit" class="button" >Submit</button>
Expand All @@ -79,9 +86,9 @@
<!-- grammar here -->
<div class="small-12 medium-6 columns" id="grammar-container">
<div id="grammarTitle">
<h3 id="grammarHeader" style="margin-bottom:0;">Consider the grammar</h3>
<h3 id="grammarHeader">Consider the grammar</h3>
<div id="grammarButtons">
<button type="button" class="button" onclick="trip.start()">Tutorial</button>
<button type="button" class="button" onclick="start_trip()">Help</button>
<button type="button" class="button" id="skip">Skip</button>
</div>
</div>
Expand All @@ -101,12 +108,24 @@ <h3 id="grammarHeader" style="margin-bottom:0;">Consider the grammar</h3>
</div>
{% endfor %}
</div>
<div id="explainer">
<p>{{ non_terminals }} is the set of nonterminal symbols</p>
<p>{{ start_symbol }} is the start symbol</p>
<p>{{ terminals }} is the set of terminal symbols</p>
<p>&epsilon; denotes the empty string</p>
<p>$ denotes end of string</p>

<div id="explainer" {% if hide_explainer == "true" %} style="display:none" {% endif %}>
<div id="explainer-flex">
<div id="explainer-text">
<p> {{ non_terminals }} is the set of nonterminal symbols</p>
<p>{{ start_symbol }} is the start symbol</p>
<p>&#123;{{ terminals }}&#125; is the set of terminal symbols</p>
<p>&epsilon; denotes the empty string</p>
<p>$ denotes end of string</p>
</div>
<div>
<button class="button" id="hideexplainer" onclick="hideexplainer()">Hide</button>
</div>
</div>

</div>
<div id="explainer-hidden" {% if not hide_explainer == "true" %} style="display:none" {% endif %} onclick="showexplainer()">
<a style="color:black;"><p>Show explainer</p></a>
</div>
</div>

Expand All @@ -118,10 +137,18 @@ <h3>Questions</h3>

{% endblock %}


{% block pagescripts %}
<script> var csrfmiddlewaretoken = "{{ csrf_token }}"; </script>
<script src="{% static 'js/learn.js' %}"></script>
<script src="{% static 'js/practice.js' %}"></script>
<link rel="stylesheet" type="text/css" href="https://oss.maxcdn.com/jquery.trip.js/3.3.3/trip.min.css"/>
<script src="https://oss.maxcdn.com/jquery.trip.js/3.3.3/trip.min.js"></script>

<script>
var terminals = "{{terminals}}".split(', ');
var grammar = JSON.parse('{{ grammar_json|safe }}');
var user_authenticated = false;
{% if user_authenticated %}
user_authenticated = true;
{% endif %}
</script>
{% endblock %}
6 changes: 4 additions & 2 deletions LL1_Academy/templates/LL1_Academy/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h3 class="table-header">Completed Grammars</h3>
{% for grammar in completed_grammars %}
<tr>
<td>
<a href="/learn/?gid={{grammar.gid}}">
<a href="/practice/?gid={{grammar.gid}}">
{{grammar.prods}}
</a>
</td>
Expand All @@ -87,7 +87,7 @@ <h3 class="table-header">Skipped Grammars</h3>
{% for grammar in skipped_grammars %}
<tr>
<td>
<a href="/learn/?gid={{grammar.gid}}">{{grammar.prods}}</a>
<a href="/practice/?gid={{grammar.gid}}">{{grammar.prods}}</a>
</td>
</tr>
{% endfor %}
Expand All @@ -109,6 +109,7 @@ <h3 class="table-header">Skipped Grammars</h3>
<script> $(window).onload = create_chart( {{chart_stats|safe}} )</script>
{% if messages %}
{% for message in messages %}
{% if not message.tags == "success" %}
<script>
swal({
title: "{% if message.tags == "info" %}Success{% else %}Oops{% endif %}",
Expand All @@ -119,6 +120,7 @@ <h3 class="table-header">Skipped Grammars</h3>
function() {
});
</script>
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}
Loading

0 comments on commit bab51f1

Please sign in to comment.