diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47685f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,128 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/CommitHistoryVisualizer/BlindCoding.gif b/CommitHistoryVisualizer/BlindCoding.gif new file mode 100644 index 0000000..f8dca75 Binary files /dev/null and b/CommitHistoryVisualizer/BlindCoding.gif differ diff --git a/CommitHistoryVisualizer/BlindCoding.mp4 b/CommitHistoryVisualizer/BlindCoding.mp4 new file mode 100644 index 0000000..71e09e8 Binary files /dev/null and b/CommitHistoryVisualizer/BlindCoding.mp4 differ diff --git a/README.md b/README.md index a11e9ce..9c01301 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,21 @@ # Blind Coding ## Bugs to be fixed/ Features to be added + - [X] Timer is not working properly, fix it -- [ ] When user gets a question correct, automatically redirect to next question -- [ ] Add a live leaderboard -- [ ] Change frontend -- [ ] Add details in about section -- [ ] Cursor does not goes up in the editor, fix it -- [ ] Do Backend stuff - do not put keys as it is within the files +- [X] When user gets a question correct, automatically redirect to next question +- [X] Add a live leaderboard +- [X] Change frontend - Leaderboard opening animation is inserted, might require to change other background colors and stuff later. +- [X] Add details in about section +- [X] Cursor does not goes up in the editor, fix it +- [X] Do Backend stuff - do not put keys as it is within the files +- [X] Add feature to show code for sometime, say 5-10 seconds once per question +- [X] Disable run button for the time compiler runs the code and returns the result to prevent multiple compiler runs +- [X] Limit number of runs per question per user - feature not needed anymore +- [X] Add Rank of the player to the leaderboard + +## Commit History Visualizer + +![GIF](CommitHistoryVisualizer/BlindCoding.gif) + +[video](CommitHistoryVisualizer/BlindCoding.mp4) \ No newline at end of file diff --git a/blind_coding/blind_coding/__pycache__/__init__.cpython-34.pyc b/blind_coding/blind_coding/__pycache__/__init__.cpython-34.pyc deleted file mode 100644 index 2f25295..0000000 Binary files a/blind_coding/blind_coding/__pycache__/__init__.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/blind_coding/__pycache__/__init__.cpython-36.pyc b/blind_coding/blind_coding/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 320943e..0000000 Binary files a/blind_coding/blind_coding/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/blind_coding/__pycache__/settings.cpython-34.pyc b/blind_coding/blind_coding/__pycache__/settings.cpython-34.pyc deleted file mode 100644 index 2314f71..0000000 Binary files a/blind_coding/blind_coding/__pycache__/settings.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/blind_coding/__pycache__/settings.cpython-36.pyc b/blind_coding/blind_coding/__pycache__/settings.cpython-36.pyc deleted file mode 100644 index 35aa34b..0000000 Binary files a/blind_coding/blind_coding/__pycache__/settings.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/blind_coding/__pycache__/urls.cpython-34.pyc b/blind_coding/blind_coding/__pycache__/urls.cpython-34.pyc deleted file mode 100644 index 6b9f58d..0000000 Binary files a/blind_coding/blind_coding/__pycache__/urls.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/blind_coding/__pycache__/urls.cpython-36.pyc b/blind_coding/blind_coding/__pycache__/urls.cpython-36.pyc deleted file mode 100644 index 3b49435..0000000 Binary files a/blind_coding/blind_coding/__pycache__/urls.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/blind_coding/__pycache__/wsgi.cpython-34.pyc b/blind_coding/blind_coding/__pycache__/wsgi.cpython-34.pyc deleted file mode 100644 index 1b36ab9..0000000 Binary files a/blind_coding/blind_coding/__pycache__/wsgi.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/blind_coding/__pycache__/wsgi.cpython-36.pyc b/blind_coding/blind_coding/__pycache__/wsgi.cpython-36.pyc deleted file mode 100644 index 7a4707c..0000000 Binary files a/blind_coding/blind_coding/__pycache__/wsgi.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/blind_coding/settings.py b/blind_coding/blind_coding/settings.py index 7aadd08..d4e7522 100644 --- a/blind_coding/blind_coding/settings.py +++ b/blind_coding/blind_coding/settings.py @@ -42,7 +42,6 @@ 'django.contrib.staticfiles', 'allauth.socialaccount.providers.google', 'main_app.apps.MainAppConfig', - ] MIDDLEWARE = [ @@ -137,3 +136,6 @@ MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(REPOSITORY_ROOT, 'media/') + +clientId = "222a2ef84f6881409d32ae21369d1a32" +clientSecret = "67872757630a355db890ee74b6b20926cb9e025dbb444182df2bd2700fc64af1" diff --git a/blind_coding/db.sqlite3 b/blind_coding/db.sqlite3 index 8d05ab6..4d8b2a7 100644 Binary files a/blind_coding/db.sqlite3 and b/blind_coding/db.sqlite3 differ diff --git a/blind_coding/main_app/__pycache__/__init__.cpython-34.pyc b/blind_coding/main_app/__pycache__/__init__.cpython-34.pyc deleted file mode 100644 index c7f38f3..0000000 Binary files a/blind_coding/main_app/__pycache__/__init__.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/__init__.cpython-36.pyc b/blind_coding/main_app/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index f8e19c5..0000000 Binary files a/blind_coding/main_app/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/admin.cpython-34.pyc b/blind_coding/main_app/__pycache__/admin.cpython-34.pyc deleted file mode 100644 index a8f9ff4..0000000 Binary files a/blind_coding/main_app/__pycache__/admin.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/admin.cpython-36.pyc b/blind_coding/main_app/__pycache__/admin.cpython-36.pyc deleted file mode 100644 index badf3bb..0000000 Binary files a/blind_coding/main_app/__pycache__/admin.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/apps.cpython-34.pyc b/blind_coding/main_app/__pycache__/apps.cpython-34.pyc deleted file mode 100644 index 54d7a46..0000000 Binary files a/blind_coding/main_app/__pycache__/apps.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/models.cpython-34.pyc b/blind_coding/main_app/__pycache__/models.cpython-34.pyc deleted file mode 100644 index 0a1b3c5..0000000 Binary files a/blind_coding/main_app/__pycache__/models.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/models.cpython-36.pyc b/blind_coding/main_app/__pycache__/models.cpython-36.pyc deleted file mode 100644 index 4b4091c..0000000 Binary files a/blind_coding/main_app/__pycache__/models.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/signals.cpython-34.pyc b/blind_coding/main_app/__pycache__/signals.cpython-34.pyc deleted file mode 100644 index 26720e7..0000000 Binary files a/blind_coding/main_app/__pycache__/signals.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/urls.cpython-34.pyc b/blind_coding/main_app/__pycache__/urls.cpython-34.pyc deleted file mode 100644 index 45c79e9..0000000 Binary files a/blind_coding/main_app/__pycache__/urls.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/urls.cpython-36.pyc b/blind_coding/main_app/__pycache__/urls.cpython-36.pyc index 303fe7b..c686f04 100644 Binary files a/blind_coding/main_app/__pycache__/urls.cpython-36.pyc and b/blind_coding/main_app/__pycache__/urls.cpython-36.pyc differ diff --git a/blind_coding/main_app/__pycache__/views.cpython-34.pyc b/blind_coding/main_app/__pycache__/views.cpython-34.pyc deleted file mode 100644 index 5ec62d0..0000000 Binary files a/blind_coding/main_app/__pycache__/views.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/__pycache__/views.cpython-36.pyc b/blind_coding/main_app/__pycache__/views.cpython-36.pyc index 22d1c81..c6d899f 100644 Binary files a/blind_coding/main_app/__pycache__/views.cpython-36.pyc and b/blind_coding/main_app/__pycache__/views.cpython-36.pyc differ diff --git a/blind_coding/main_app/admin.py b/blind_coding/main_app/admin.py index 9e89a0c..3f569ee 100644 --- a/blind_coding/main_app/admin.py +++ b/blind_coding/main_app/admin.py @@ -1,7 +1,8 @@ from __future__ import unicode_literals from django.contrib import admin -from .models import Question,Userdata +from .models import Question,Userdata,Time_Penalty # Register your models here. admin.site.register(Question) admin.site.register(Userdata) +admin.site.register(Time_Penalty) \ No newline at end of file diff --git a/blind_coding/main_app/migrations/0001_initial.py b/blind_coding/main_app/migrations/0001_initial.py index 2332569..47557c3 100644 --- a/blind_coding/main_app/migrations/0001_initial.py +++ b/blind_coding/main_app/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.0.13 on 2019-03-21 14:30 +# Generated by Django 2.2.7 on 2020-01-03 18:07 from django.conf import settings from django.db import migrations, models @@ -20,6 +20,9 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('qno', models.IntegerField(default=0)), ('text', models.CharField(max_length=45000)), + ('testcaseno', models.IntegerField(default=0)), + ('samplein', models.CharField(default='', max_length=45000)), + ('sampleout', models.CharField(default='', max_length=45000)), ('test_case1', models.CharField(max_length=1000)), ('test_case2', models.CharField(max_length=1000)), ('test_case3', models.CharField(max_length=1000)), @@ -33,6 +36,9 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=100)), + ('score', models.IntegerField(default=0)), + ('answerGiven', models.CharField(default='00000', max_length=10)), + ('timeElapsed', models.IntegerField(default=0)), ('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], ), diff --git a/blind_coding/main_app/migrations/0002_auto_20200104_1324.py b/blind_coding/main_app/migrations/0002_auto_20200104_1324.py new file mode 100644 index 0000000..a500cd2 --- /dev/null +++ b/blind_coding/main_app/migrations/0002_auto_20200104_1324.py @@ -0,0 +1,43 @@ +# Generated by Django 2.2.7 on 2020-01-04 07:54 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('main_app', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='question', + name='weight', + field=models.IntegerField(default=10), + preserve_default=False, + ), + migrations.AddField( + model_name='userdata', + name='total_penalty', + field=models.IntegerField(default=0), + ), + migrations.CreateModel( + name='Time_Penalty', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('time_penalty', models.IntegerField(default=0)), + ('no_wa', models.IntegerField(default=0)), + ('player', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main_app.Userdata')), + ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='questions', to='main_app.Question')), + ], + options={ + 'unique_together': {('player', 'question')}, + }, + ), + migrations.AddField( + model_name='question', + name='time_penalty', + field=models.ManyToManyField(blank=True, null=True, through='main_app.Time_Penalty', to='main_app.Userdata'), + ), + ] diff --git a/blind_coding/main_app/migrations/0002_question_qno.py b/blind_coding/main_app/migrations/0002_question_qno.py deleted file mode 100644 index 8e01c0c..0000000 --- a/blind_coding/main_app/migrations/0002_question_qno.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.1.7 on 2019-02-28 12:32 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main_app', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='question', - name='qno', - field=models.IntegerField(default=0), - ), - ] diff --git a/blind_coding/main_app/migrations/0003_auto_20190328_2312.py b/blind_coding/main_app/migrations/0003_auto_20190328_2312.py deleted file mode 100644 index 86d9183..0000000 --- a/blind_coding/main_app/migrations/0003_auto_20190328_2312.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 2.0.13 on 2019-03-28 17:42 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main_app', '0002_question_qno'), - ] - - operations = [ - migrations.AddField( - model_name='question', - name='samplein', - field=models.CharField(default='', max_length=45000), - ), - migrations.AddField( - model_name='question', - name='sampleout', - field=models.CharField(default='', max_length=45000), - ), - ] diff --git a/blind_coding/main_app/migrations/0003_auto_20200104_1332.py b/blind_coding/main_app/migrations/0003_auto_20200104_1332.py new file mode 100644 index 0000000..ff0fc09 --- /dev/null +++ b/blind_coding/main_app/migrations/0003_auto_20200104_1332.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.7 on 2020-01-04 08:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main_app', '0002_auto_20200104_1324'), + ] + + operations = [ + migrations.AlterField( + model_name='question', + name='weight', + field=models.IntegerField(default=20), + ), + ] diff --git a/blind_coding/main_app/migrations/0004_question_testcaseno.py b/blind_coding/main_app/migrations/0004_question_testcaseno.py deleted file mode 100644 index 7139280..0000000 --- a/blind_coding/main_app/migrations/0004_question_testcaseno.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.0.13 on 2019-03-28 17:47 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main_app', '0003_auto_20190328_2312'), - ] - - operations = [ - migrations.AddField( - model_name='question', - name='testcaseno', - field=models.IntegerField(default=0), - ), - ] diff --git a/blind_coding/main_app/migrations/0005_userdata_score.py b/blind_coding/main_app/migrations/0004_userdata_chancesused.py similarity index 67% rename from blind_coding/main_app/migrations/0005_userdata_score.py rename to blind_coding/main_app/migrations/0004_userdata_chancesused.py index 35e682f..56bef1c 100644 --- a/blind_coding/main_app/migrations/0005_userdata_score.py +++ b/blind_coding/main_app/migrations/0004_userdata_chancesused.py @@ -1,4 +1,4 @@ -# Generated by Django 2.0.13 on 2019-03-28 20:52 +# Generated by Django 2.2.7 on 2020-01-11 10:40 from django.db import migrations, models @@ -6,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('main_app', '0004_question_testcaseno'), + ('main_app', '0003_auto_20200104_1332'), ] operations = [ migrations.AddField( model_name='userdata', - name='score', + name='chancesUsed', field=models.IntegerField(default=0), ), ] diff --git a/blind_coding/main_app/migrations/0006_question_correctanswered.py b/blind_coding/main_app/migrations/0006_question_correctanswered.py deleted file mode 100644 index 14f6228..0000000 --- a/blind_coding/main_app/migrations/0006_question_correctanswered.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.0.13 on 2019-03-28 23:13 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main_app', '0005_userdata_score'), - ] - - operations = [ - migrations.AddField( - model_name='question', - name='correctAnswered', - field=models.IntegerField(default=0), - ), - ] diff --git a/blind_coding/main_app/migrations/0007_auto_20190329_0445.py b/blind_coding/main_app/migrations/0007_auto_20190329_0445.py deleted file mode 100644 index 9ede53a..0000000 --- a/blind_coding/main_app/migrations/0007_auto_20190329_0445.py +++ /dev/null @@ -1,42 +0,0 @@ -# Generated by Django 2.0.13 on 2019-03-28 23:15 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main_app', '0006_question_correctanswered'), - ] - - operations = [ - migrations.RemoveField( - model_name='question', - name='correctAnswered', - ), - migrations.AddField( - model_name='userdata', - name='correctAnswered0', - field=models.IntegerField(default=0), - ), - migrations.AddField( - model_name='userdata', - name='correctAnswered1', - field=models.IntegerField(default=0), - ), - migrations.AddField( - model_name='userdata', - name='correctAnswered2', - field=models.IntegerField(default=0), - ), - migrations.AddField( - model_name='userdata', - name='correctAnswered3', - field=models.IntegerField(default=0), - ), - migrations.AddField( - model_name='userdata', - name='correctAnswered4', - field=models.IntegerField(default=0), - ), - ] diff --git a/blind_coding/main_app/migrations/0008_auto_20190329_0509.py b/blind_coding/main_app/migrations/0008_auto_20190329_0509.py deleted file mode 100644 index 66741c0..0000000 --- a/blind_coding/main_app/migrations/0008_auto_20190329_0509.py +++ /dev/null @@ -1,38 +0,0 @@ -# Generated by Django 2.0.13 on 2019-03-28 23:39 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main_app', '0007_auto_20190329_0445'), - ] - - operations = [ - migrations.RemoveField( - model_name='userdata', - name='correctAnswered0', - ), - migrations.RemoveField( - model_name='userdata', - name='correctAnswered1', - ), - migrations.RemoveField( - model_name='userdata', - name='correctAnswered2', - ), - migrations.RemoveField( - model_name='userdata', - name='correctAnswered3', - ), - migrations.RemoveField( - model_name='userdata', - name='correctAnswered4', - ), - migrations.AddField( - model_name='userdata', - name='answer', - field=models.CharField(default='00000', max_length=5), - ), - ] diff --git a/blind_coding/main_app/migrations/0009_auto_20190329_0613.py b/blind_coding/main_app/migrations/0009_auto_20190329_0613.py deleted file mode 100644 index cbca258..0000000 --- a/blind_coding/main_app/migrations/0009_auto_20190329_0613.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.0.13 on 2019-03-29 00:43 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main_app', '0008_auto_20190329_0509'), - ] - - operations = [ - migrations.AlterField( - model_name='userdata', - name='answer', - field=models.CharField(default='00000', max_length=10), - ), - ] diff --git a/blind_coding/main_app/migrations/0010_auto_20190329_0616.py b/blind_coding/main_app/migrations/0010_auto_20190329_0616.py deleted file mode 100644 index 4053f76..0000000 --- a/blind_coding/main_app/migrations/0010_auto_20190329_0616.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.0.13 on 2019-03-29 00:46 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('main_app', '0009_auto_20190329_0613'), - ] - - operations = [ - migrations.RenameField( - model_name='userdata', - old_name='answer', - new_name='answerGiven', - ), - ] diff --git a/blind_coding/main_app/migrations/0011_userdata_timeelapsed.py b/blind_coding/main_app/migrations/0011_userdata_timeelapsed.py deleted file mode 100644 index 19bf0c7..0000000 --- a/blind_coding/main_app/migrations/0011_userdata_timeelapsed.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.0.13 on 2019-03-29 10:15 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main_app', '0010_auto_20190329_0616'), - ] - - operations = [ - migrations.AddField( - model_name='userdata', - name='timeElapsed', - field=models.IntegerField(default=0), - ), - ] diff --git a/blind_coding/main_app/migrations/__pycache__/0001_initial.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0001_initial.cpython-34.pyc deleted file mode 100644 index bc2784e..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0001_initial.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0001_initial.cpython-36.pyc b/blind_coding/main_app/migrations/__pycache__/0001_initial.cpython-36.pyc deleted file mode 100644 index c86802b..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0001_initial.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0002_question_qno.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0002_question_qno.cpython-34.pyc deleted file mode 100644 index e7edc1d..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0002_question_qno.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0002_question_qno.cpython-36.pyc b/blind_coding/main_app/migrations/__pycache__/0002_question_qno.cpython-36.pyc deleted file mode 100644 index 1faadbf..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0002_question_qno.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0003_auto_20190328_2312.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0003_auto_20190328_2312.cpython-34.pyc deleted file mode 100644 index 251724d..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0003_auto_20190328_2312.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0004_question_testcaseno.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0004_question_testcaseno.cpython-34.pyc deleted file mode 100644 index 0485589..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0004_question_testcaseno.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0005_userdata_score.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0005_userdata_score.cpython-34.pyc deleted file mode 100644 index f1c6a86..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0005_userdata_score.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0006_question_correctanswered.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0006_question_correctanswered.cpython-34.pyc deleted file mode 100644 index 83bdaa1..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0006_question_correctanswered.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0007_auto_20190329_0445.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0007_auto_20190329_0445.cpython-34.pyc deleted file mode 100644 index f3b6470..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0007_auto_20190329_0445.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0008_auto_20190329_0509.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0008_auto_20190329_0509.cpython-34.pyc deleted file mode 100644 index 9de7703..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0008_auto_20190329_0509.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0009_auto_20190329_0613.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0009_auto_20190329_0613.cpython-34.pyc deleted file mode 100644 index bc3d37d..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0009_auto_20190329_0613.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0010_auto_20190329_0616.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0010_auto_20190329_0616.cpython-34.pyc deleted file mode 100644 index 912a628..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0010_auto_20190329_0616.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/0011_userdata_timeelapsed.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/0011_userdata_timeelapsed.cpython-34.pyc deleted file mode 100644 index 418eaf6..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/0011_userdata_timeelapsed.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/__init__.cpython-34.pyc b/blind_coding/main_app/migrations/__pycache__/__init__.cpython-34.pyc deleted file mode 100644 index 5cadd58..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/__init__.cpython-34.pyc and /dev/null differ diff --git a/blind_coding/main_app/migrations/__pycache__/__init__.cpython-36.pyc b/blind_coding/main_app/migrations/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index e2d02e2..0000000 Binary files a/blind_coding/main_app/migrations/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/blind_coding/main_app/models.py b/blind_coding/main_app/models.py index f58d542..0eb95af 100644 --- a/blind_coding/main_app/models.py +++ b/blind_coding/main_app/models.py @@ -6,15 +6,19 @@ class Userdata(models.Model): user_id=models.ForeignKey(User,on_delete=models.CASCADE) name=models.CharField(max_length=100) score = models.IntegerField(default = 0) + chancesUsed = models.IntegerField(default = 0) answerGiven = models.CharField(max_length = 10, default="00000") timeElapsed = models.IntegerField(default = 0) - + total_penalty=models.IntegerField(default = 0) + def __str__(self): return str(self.user_id.username) class Question(models.Model): qno=models.IntegerField(default=0) + weight = models.IntegerField(default=20) text = models.CharField(max_length=45000) + time_penalty = models.ManyToManyField(Userdata, through="Time_Penalty",blank=True,null=True) testcaseno=models.IntegerField(default=0) samplein = models.CharField(max_length=45000,default='') sampleout = models.CharField(max_length=45000,default='') @@ -27,3 +31,15 @@ class Question(models.Model): def __str__(self): return str(self.pk) + +class Time_Penalty(models.Model): + player = models.ForeignKey(Userdata, on_delete=models.CASCADE) + question = models.ForeignKey(Question, on_delete=models.CASCADE,related_name='questions') + time_penalty = models.IntegerField(default=0) + no_wa = models.IntegerField(default=0) + + class Meta: + unique_together = ("player", "question") + + def __str__(self): + return "{} : {}".format(self.player.name, self.question.qno) diff --git a/blind_coding/main_app/templates/index.html b/blind_coding/main_app/templates/index.html index 161d8f5..df1272e 100644 --- a/blind_coding/main_app/templates/index.html +++ b/blind_coding/main_app/templates/index.html @@ -14,20 +14,24 @@
-
-
- - -
-

Instructions

-

1. What is Lorem Ipsum?

-

2. Where does it come from?

- -
+
+
+ + +
+

Instructions

+
- There are five questions of varying difficulties and points associated with them.
Score associated are 20, 30, 40, 50, 60 points respectively.
+
- For every question, the first time you submit the correct answer, you are awarded points corresponding to that question and the time penalty is + also calculated which takes into consideration the time taken until last successful solve together with the number of wrong attempts
+
- Standings will be based on the points scored and in cases of clashes, time penalties are compared and one with lesser time penalty is better ranker
+
- Every time you give a correct answer, the question is automatically changed and code editor is reset.
+
- You have only two attempts throughout the event to see the code you have written. To see the code, press Show Code button near Run button.
+
- Don't try to open up the console or changing the window/tab. You'll be logged out immediately
+
@@ -51,6 +55,7 @@

2. Where does it come from?

- + + \ No newline at end of file diff --git a/blind_coding/main_app/templates/loggedIn.html b/blind_coding/main_app/templates/loggedIn.html index ef6d19b..ad60a51 100644 --- a/blind_coding/main_app/templates/loggedIn.html +++ b/blind_coding/main_app/templates/loggedIn.html @@ -11,6 +11,7 @@ + @@ -60,29 +61,33 @@
-
-
+
+
-

About

-
1. What is Lorem Ipsum?
-

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

-
2. Where does it come from?
-

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested.

-
+

Instructions

+
- There are five questions of varying difficulties and points associated with them.
Score associated are 20, 40, 60, 80, 100 points respectively.
+
- For every question, the first time you submit the correct answer, you are awarded points corresponding to that question and the time penalty is + also calculated which takes into consideration the time taken until last successful solve together with the number of wrong attempts
+
- Standings will be based on the points scored and in cases of clashes, time penalties are compared and one with lesser time penalty is better ranker
+
- Every time you give a correct answer, the question is automatically changed and code editor is reset.
+
- You have only two attempts throughout the event to see the code you have written. To see the code, press Show Code button near Run button.
+
- Don't try to open up the console or changing the window/tab. You'll be logged out immediately
+

Blind Coding

+
Question 1
- You have C=100,000 cakes, numbered 1 through C. Each cake has an integer height; initially, the height of each cake is 0. There are N operations. In each operation, you are given two integers L and R, and you should increase by 1 the height of each of the cakes L,L+1,…,R. One of these N operations should be removed and the remaining N−1 operations are then performed. Chef wants to remove one operation in such a way that after the remaining N−1 operations are performed, the number of cakes with height exactly K is maximum possible. Since Chef is a bit busy these days, he has asked for your help. You need to find the maximum number of cakes with height exactly K that can be achieved by removing one operation. + Loading.....
@@ -90,12 +95,12 @@
Question 1
@@ -109,7 +114,9 @@
Question 1
- + + +
@@ -122,30 +129,72 @@
Question 1
insert_chart
- - - - - - - - - - - - - - - - +
RankNamePoints
1DM50
2BK10
+ + + + + + + + + + + + + + + + + + + +
Rank (Your Rank: )NamePoints
Loading...
1
- +

© Coding Club ,2019

+ + + + + + diff --git a/blind_coding/main_app/urls.py b/blind_coding/main_app/urls.py index 6ed3ec0..fa2b349 100644 --- a/blind_coding/main_app/urls.py +++ b/blind_coding/main_app/urls.py @@ -2,15 +2,16 @@ from django.urls import path,include,re_path from . import views - app_name='quiz' urlpatterns=[ - path('main/',views.default), - path('',views.index), - path('login/',views.login), - path('logout/',views.l_out), - path('question/',views.question, name='question'), - path('main/runCode/',views.runCode, name='runCode') - + path('main/', views.default, name='main'), + path('', views.index, name='index'), + path('login/', views.login, name='login'), + path('logout/', views.l_out, name='logout'), + path('question/', views.question, name='question'), + path('main/runCode/', views.runCode, name='runCode'), + path('leaderboard/', views.leaderboard, name='leaderboard'), + path('getChancesUsed/', views.getChancesUsed, name='getChancesUsed'), + path('increaseClicks/', views.increaseClicks, name='increaseClicks'), ] diff --git a/blind_coding/main_app/views.py b/blind_coding/main_app/views.py index 1f0e3d3..afc4dd8 100644 --- a/blind_coding/main_app/views.py +++ b/blind_coding/main_app/views.py @@ -1,23 +1,21 @@ from django.shortcuts import render,redirect -import requests - -# Create your views here. -def default(request): - return render(request,'loggedIn.html') - -def index(request): - return render(request,'index.html') -# -#def login(request): -# pass from django.shortcuts import render from django.http import JsonResponse,HttpResponseRedirect,HttpResponse -from .models import Userdata,Question +from .models import Userdata,Question,Time_Penalty from django.contrib.auth import logout +from django.contrib.auth.decorators import login_required + import json +import requests +import base64 +import time +import blind_coding.settings as settings -from django.contrib.auth.decorators import login_required +def default(request): + return render(request,'loggedIn.html') +def index(request): + return render(request,'index.html') def login(request): # if request.POST: @@ -47,48 +45,124 @@ def question(request): print('hi') print(res['userScore']) return HttpResponse(json.dumps(res)) - + def runCode(request): postData = json.loads( request.body.decode('utf-8') ) - url = 'https://api.jdoodle.com/execute/' -# print(postData) + url = 'https://api.judge0.com/submissions?base64_encoded=false&wait=false' que = Question.objects.get(qno=postData['qNo']) - postData['stdin'] = '3'+'\n'+que.test_case1+'\n'+que.test_case2+'\n'+que.test_case3 + stdin = '3'+'\n'+que.test_case1+'\n'+que.test_case2+'\n'+que.test_case3 + # postData['stdin'] = str(base64.b64encode(stdin.encode("utf-8"))) + postData['stdin'] = stdin + # postData['source_code'] = str(base64.b64encode(postData['source_code'].encode('utf-8'))) + print(postData) + response = requests.post(url,json=postData) resp = response.json() -# resp = json.loads(resp) - print(postData['qNo']) + # resp = json.loads(resp) + print('qNo',postData['qNo']) + print('response token: ',resp['token']) + + url2 = 'https://api.judge0.com/submissions/'+resp['token']+'?base64_encoded=false' + time.sleep(1) + resp = requests.get(url2).json() + if 'status' in resp: + if resp['status']['description'] == "Processing": + while resp['status']['description'] == "Processing": + resp = requests.get(url2).json() print(resp) - print(resp['output']) + # print('exit_code ',resp['exit_code']) + # print('exit_signal ',resp['exit_signal']) + # print( str(base64.b64decode(resp['stderr'].encode('utf-8').strip()), "utf-8") ) + # print('output response: ',resp['stdout']) res = {} - if resp['output'].find('error') != -1: - res['output'] = resp['output'] + #Get current user + currUser = Userdata.objects.get(user_id = request.user) + if 'error' in resp: + res['stdout'] = 'error' + elif resp['status']['description'] != "Accepted": + if resp['stderr'] is not None: + res['stdout'] = resp['stderr'] + elif resp['compile_output'] is not None: + res['stdout'] = resp['compile_output'] + else: + res['stdout'] = 'error' else: - quesData = Question.objects.get(qno=postData['qNo']) + quesNo = postData['qNo'] + quesData = Question.objects.get(qno= quesNo) answer = quesData.test_case1_sol+'\n'+quesData.test_case2_sol+'\n'+quesData.test_case3_sol+'\n' print(answer) - currUser = Userdata.objects.get(user_id = request.user) currUser.timeElapsed += int(postData['timeElapsed']) - if answer == resp['output']: + if answer == resp['stdout']: print('hurray') - res['output'] = 'Correct Answer' + res['stdout'] = 'Correct Answer' print(currUser.answerGiven) lst = list(currUser.answerGiven) print(lst) - if(lst[postData['qNo']] == '0'): - print('qwer') - currUser.score+=10 + if(lst[quesNo] == '0'): # if the question is being answered first time + print('Updating score for question no', ) + lst[quesNo] = '1' + currUser.answerGiven="".join(lst) + timepenalty , status =Time_Penalty.objects.get_or_create(player=currUser,question=que) + timepenalty.time_penalty=int(postData['timeElapsed'])+(0.2*timepenalty.no_wa*que.weight) + currUser.score+=que.weight + currUser.total_penalty+=timepenalty.time_penalty + timepenalty.save() currUser.save() - lst[postData['qNo']] = '1'; - currUser.answerGiven="".join(lst) - else: - res['output'] = 'Wrong answer..' - - currUser.save() - res['score'] = currUser.score + timepenalty , status = Time_Penalty.objects.get_or_create(player=currUser,question=que) + print('hiii') + print('hola: ',timepenalty) + print('timepenalty_player',timepenalty.player) + timepenalty.no_wa+=1 + res['stdout'] = 'Wrong answer..' + timepenalty.save() + currUser.save() + res['score'] = currUser.score + if currUser.answerGiven == "11111": + res['completedGame'] = 'true' + else: + res['completedGame'] = 'false' return HttpResponse(json.dumps(res)) def l_out(request): - logout(request) - return render(request,'index.html') \ No newline at end of file + logout(request) + return render(request,'index.html') + +def leaderboard(request): + leaderboard = Userdata.objects.order_by('-score','total_penalty') + print(leaderboard) + username = [] + score = [] + for i in range(10): + try: + username.append(leaderboard[i].name) + score.append(leaderboard[i].score) + except: + pass + + curr_user = Userdata.objects.get(user_id=request.user) + curr_score = curr_user.score + rank = 1 + for player in leaderboard: + if curr_user == player: + break + if curr_score <= player.score: + rank += 1 + + resp = {'username': username, 'score': score, 'rank': rank} + return HttpResponse(json.dumps(resp), content_type='application/json') + +def getChancesUsed(request): + res={} + res['chancesUsed'] = Userdata.objects.get(user_id = request.user).chancesUsed + return HttpResponse(json.dumps(res)) + +def increaseClicks(request): + data = json.loads( request.body.decode('utf-8') ) + clicks = data['clicks'] + user = Userdata.objects.get(user_id = request.user) + user.chancesUsed = clicks + user.save() + res = {} + res['error'] = 'No Error' + return HttpResponse(json.dumps(res)) \ No newline at end of file diff --git a/blind_coding/static/assets/apogeeLogo.png b/blind_coding/static/assets/apogeeLogo.png index 8a2f06d..7d71b9d 100644 Binary files a/blind_coding/static/assets/apogeeLogo.png and b/blind_coding/static/assets/apogeeLogo.png differ diff --git a/blind_coding/static/css/style-1.css b/blind_coding/static/css/style-1.css index 66a7783..5621897 100644 --- a/blind_coding/static/css/style-1.css +++ b/blind_coding/static/css/style-1.css @@ -37,7 +37,7 @@ outline: none; background: rgba(0,0,0,0.8); } -.about { +.instructions { color: white; display: none; position: absolute; @@ -154,6 +154,13 @@ nav#header ul a { sizing: expand; } +#main > .qno { + color: white; + font-size: 16px; + padding: 25px 15px; + sizing: expand; +} + .left h4 { margin: 0 0 10px 0; } @@ -178,8 +185,8 @@ nav#header ul a { .options { display: flex; - margin: 8px 0 0 0; - justify-content: space-around; + margin: 15px 0 0 0; + justify-content: center; } button { @@ -287,8 +294,14 @@ textarea:focus { background: black; } -.run,.submit{ +.bttn,.submit, #showCode{ width: 10vw; + background-color: rgba(57, 255, 216, 0.8); + transition: all 100ms ease-in 50ms; +} + +.bttn:nth-child(1) { + margin-right: 3.5vw; } #footer p { @@ -408,6 +421,10 @@ tr td, tr th { width: 20px; } +.hdrank{ + width:170px; +} + /* Sidenav */ .hamburger { @@ -501,12 +518,7 @@ tr td, tr th { transition-delay: 0s; } -* { - -webkit-transition: 0.25s all ease; - -moz-transition: 0.25s all ease; - -o-transition: 0.25s all ease; - transition: 0.25s all ease; -} + /* Sidenav body */ @@ -588,9 +600,28 @@ a { #codeInput{ color: black; - caret-color: white; + caret-color: white; + transition: color 100ms ease-out; +} + +#codeInput::selection{ + color:black; + background:none; +} + +#codeInput::-moz-selection{ + color:black; + background:none; } ::selection{ background: black; -} \ No newline at end of file +} + +table thead th{ + position:sticky; + top:0; + z-index: 9; + background-color: black; + background-attachment: fixed; +} diff --git a/blind_coding/static/css/style.css b/blind_coding/static/css/style.css index 117cf79..8a67107 100644 --- a/blind_coding/static/css/style.css +++ b/blind_coding/static/css/style.css @@ -29,7 +29,7 @@ body, html { background: rgba(0,0,0,0.8); } -.about { +.instructions { color: white; display: none; position: absolute; diff --git a/blind_coding/static/js/app.js b/blind_coding/static/js/app.js index 83db371..d527c9e 100644 --- a/blind_coding/static/js/app.js +++ b/blind_coding/static/js/app.js @@ -1,281 +1,294 @@ -// var request = require('request'); +let ctrlDown = false; +let ctrlKey = 17, cmdKey = 91, vKey = 86, cKey = 67; +let qNo = 0; +let languageIDs = JSON.parse("[{\"id\":45,\"name\":\"Assembly (NASM 2.14.02)\"},{\"id\":46,\"name\":\"Bash (5.0.0)\"},{\"id\":47,\"name\":\"Basic (FBC 1.07.1)\"},{\"id\":48,\"name\":\"C (GCC 7.4.0)\"},{\"id\":52,\"name\":\"C++ (GCC 7.4.0)\"},{\"id\":49,\"name\":\"C (GCC 8.3.0)\"},{\"id\":53,\"name\":\"C++ (GCC 8.3.0)\"},{\"id\":50,\"name\":\"C (GCC 9.2.0)\"},{\"id\":54,\"name\":\"C++ (GCC 9.2.0)\"},{\"id\":51,\"name\":\"C# (Mono 6.6.0.161)\"},{\"id\":55,\"name\":\"Common Lisp (SBCL 2.0.0)\"},{\"id\":56,\"name\":\"D (DMD 2.089.1)\"},{\"id\":57,\"name\":\"Elixir (1.9.4)\"},{\"id\":58,\"name\":\"Erlang (OTP 22.2)\"},{\"id\":44,\"name\":\"Executable\"},{\"id\":59,\"name\":\"Fortran (GFortran 9.2.0)\"},{\"id\":60,\"name\":\"Go (1.13.5)\"},{\"id\":61,\"name\":\"Haskell (GHC 8.8.1)\"},{\"id\":62,\"name\":\"Java (OpenJDK 13.0.1)\"},{\"id\":63,\"name\":\"JavaScript (Node.js 12.14.0)\"},{\"id\":64,\"name\":\"Lua (5.3.5)\"},{\"id\":65,\"name\":\"OCaml (4.09.0)\"},{\"id\":66,\"name\":\"Octave (5.1.0)\"},{\"id\":67,\"name\":\"Pascal (FPC 3.0.4)\"},{\"id\":68,\"name\":\"PHP (7.4.1)\"},{\"id\":43,\"name\":\"Plain Text\"},{\"id\":69,\"name\":\"Prolog (GNU Prolog 1.4.5)\"},{\"id\":70,\"name\":\"Python (2.7.17)\"},{\"id\":71,\"name\":\"Python (3.8.1)\"},{\"id\":72,\"name\":\"Ruby (2.7.0)\"},{\"id\":73,\"name\":\"Rust (1.40.0)\"},{\"id\":74,\"name\":\"TypeScript (3.7.4)\"}]"); +let timerCont = document.getElementById('timer'); +let s = 0, m = 0; +let timerId; +const _totalNumQues = 5; +let codeMap= new Map(); $(document).ready(function() { - var inp = document.getElementsByClassName('noselect')[0]; -getQuestion(0); -inp.addEventListener('select', function() { - this.selectionStart = this.selectionEnd; -}, false); - - document.addEventListener('contextmenu', event => event.preventDefault()); - var ctrlDown = false, - ctrlKey = 17, - cmdKey = 91, - vKey = 86, - cKey = 67; + for(var i=0; i<_totalNumQues; i++){ + codeMap.set(i, null) + } + populateLangs(); + getQuestion(0); + disableCopyPaste(); + leaderbInit(); + increaseTime(); + hideCode(); + addResizeEvent(); + showBtnInit(); + sideNavInit(); +}); - $(document).keydown(function(e) { - if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = true; - }).keyup(function(e) { - if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = false; - }); +function showBtnInit(){ + document.getElementById('showCode').addEventListener('click', () => { + showCode() + }); +} - $(".no-copy-paste").keydown(function(e) { - if (ctrlDown && (e.keyCode == vKey || e.keyCode == cKey)) return false; - }); - - // Document Ctrl + C/V - $(document).keydown(function(e) { - if (ctrlDown && (e.keyCode == cKey)) console.log("Document catch Ctrl+C"); - if (ctrlDown && (e.keyCode == vKey)) console.log("Document catch Ctrl+V"); - }); +function addResizeEvent(){ + window.onresize = function() { + if ((window.outerHeight - window.innerHeight) > 100) { + logout('screen-resize') + } + } +} +function leaderbInit(){ let i = 0; $('.leaderboard-icon').click(function() { - $('.leaderboard').fadeToggle(); + $('.leaderboard').fadeToggle(650, "swing"); if (i === 0) { $('.li').html('cancel'); i = 1 + getLeaderboard(); // insert_chart } else { $('.li').html('insert_chart') i = 0; } - }) -}); -const languages = ['c','java','cpp','cpp14','python2','python3']; - -const versions = ['0','1','2']; - -var code = ` -#include -int main(){ - printf("Hello World num entered is :"); - return 0; -}`; + }); +} +function disableCopyPaste(){ + var inp = document.getElementsByClassName('noselect')[0]; + inp.addEventListener('select', function() { + this.selectionStart = this.selectionEnd; + }, false); + document.addEventListener('contextmenu', event => event.preventDefault()); + $(document).keydown(function(e) { + // console.log('Key pressed: ', e.keyCode); + if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = true; + }).keyup(function(e) { + // console.log('Key released: ', e.keyCode); + if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = false; + }); -let langNo = 0; -let versionNo = 0; -let input = '1'; -let output = ''; -let qNo=0; -let tc1 = ''; -let tc2 = ''; -let tc3 = ''; + $(".no-copy-paste").keydown(function(e) { + // console.log('Key pressed inside editor: ', e.keyCode); + if(ctrlDown && (e.keyCode == cKey)) + { + console.log("Document catch Ctrl+C"); + } + if(ctrlDown && (e.keyCode == vKey)){ + console.log("Document catch Ctrl+V"); + } + if (ctrlDown && (e.keyCode == vKey || e.keyCode == cKey)){ + // console.log('copy-paste'); + return false; + } + }); +} -const setCode = (prog)=>{ - code = prog; -}; +function populateLangs() +{ + console.log('populating languages...'); + + let selectField = document.getElementById('langSelect'); + for(element of languageIDs) + { + var opt = document.createElement("option"); + opt.value= element['id']; + opt.innerHTML = element['name']; + selectField.appendChild(opt); + } +} -const getCode = () => { - return code; -}; +function logout(reason){ + if(reason == 'Finished'){ + Swal.fire( + 'Congratulations', + 'You have successfully attempted all the questions', + 'success' + ); + } + else if(reason == 'screen-resize'){ + Swal.fire( + 'Sorry', + "You will be logged out since you didn't follow the instructions", + 'error' + ); + } + window.location.href = "/logout"; +} +function resetTime(){ + s = 0; + m = 0; +} -const setLanguage = (langNum) => { - langNo = langNum; -}; +function setOutput(outp) { + document.getElementById("compilerOutput").value = outp; +} -const getLanguage = () => { - return langNo; -}; +function setScore(score){ + document.getElementById('score').innerHTML = score; +} +function getOutput(){ + return document.getElementById("compilerOutput").value; +} -const setVersion = (vrsn) => { - versionNo = vrsn; -}; +function increaseQNum(){ + qNo = (getQNum() + 1) % _totalNumQues; +} -const getVersion = () => { - return versions[versionNo]; +function getQNum() { + return qNo; } -const setCustomInput = (inp)=>{ - input = inp; +function getCode(){ + return document.getElementById("codeInput").value; } -const getCustomInput = ()=>{ - return input; +function getLanguage(){ + return document.getElementById("langSelect").value; } -const setOutput = (outp) => { - console.log('Result:',outp); - output = outp; -}; +function disableRun(){ + document.getElementById('runBtn').disabled = true; +} -const getOutput = () => { - return output; -}; +function enableRun(){ + document.getElementById('runBtn').disabled = false; +} -const runCode = () => { - stopClock(); - console.log('time elapsed is: ',start); - let prog = document.getElementById("codeInput").value; - setCode(prog); +function runCode(){ + disableRun(); + pauseTime(); + console.log(`Time elapsed is: ${m} minutes and ${s} seconds`); - let lang = document.getElementById("langSelect").value; - setLanguage(lang); + let prog = getCode(); - console.log('Language: ',getLanguage(),'code: ',getCode()); + let lang = getLanguage(); + let time = m * 60 + s; - var program = { - script : getCode(), - language: getLanguage(), - versionIndex: getVersion(), - clientId: "222a2ef84f6881409d32ae21369d1a32", - clientSecret:"67872757630a355db890ee74b6b20926cb9e025dbb444182df2bd2700fc64af1", - stdin: getCustomInput(), //to give custom input - qNo: getQNum(), - timeElapsed: start + let program = { + source_code : prog, + language_id: lang, + qNo: getQNum(), + timeElapsed: time }; - //just send this object to jdoodle url and send back the response - // for all test cases backend checks the output and returns no of test cases cleared - let resp = sendRequest('POST','runCode/',program); - - -}; + sendRequest('POST', 'runCode/', program).then( + function(response){ + response = JSON.parse(response); + console.log('Compiler Call Response: ', response); + setOutput(response['stdout']); + setScore(response['score']); + if(getOutput() == 'Correct Answer') + { + if(response['completedGame'] == 'true'){ + logout('Finished'); + } + resetTime(); + increaseQNum(); + getQuestion(qNo); + } + increaseTime(); + enableRun(); + } + ).catch( + function(error){ + increaseTime(); + enableRun(); + console.error(error); + } + ); +} function getCookie(name) { var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)'); return v ? v[2] : null; } - -const sendRequest = (method,url,data) => { - var csrf_token = getCookie('csrftoken'); - var ourRequest = new XMLHttpRequest(); - ourRequest.open(method,url, true); - ourRequest.setRequestHeader("Content-type", "application/json"); - ourRequest.setRequestHeader("X-CSRFToken", csrf_token); - ourRequest.onload = function() { - if (ourRequest.status >= 200 && ourRequest.status < 400) { - if(url == 'runCode/'){ - let recievedData = JSON.parse(ourRequest.responseText); - setOutput(recievedData); - document.getElementById("compilerOutput").value = getOutput().output; - document.getElementById('score').innerHTML = recievedData['score']; - console.log(recievedData['score']); - if(getOutput().output == 'Correct Answer') - start = 0; -// startClock(); - return recievedData; - } - else{ - let recievedData = JSON.parse(ourRequest.responseText); - let inpt = recievedData['sampIn'].split(' '); - let inStr = ''; - for(let i=0;i
'+'Sample Input'+'
'+recievedData['sampTCNum']+'
'+inStr+'

'+'Sample Output'+'
'+recievedData['sampleOut']; - console.log('hi ',recievedData); - document.getElementsByClassName('left')[0].innerHTML=que; - qNo = recievedData['qNo']; - console.log(qNo); - console.log(recievedData['userScore']); - document.getElementById('score').innerHTML = recievedData['userScore']; - return recievedData; - } +function sendRequest(type, url, data){ + let request = new XMLHttpRequest(); + let csrftoken = getCookie("csrftoken"); + return new Promise(function(resolve, reject){ + request.onreadystatechange = () => { + if (request.readyState !== 4) return; + // Process the response + if (request.status >= 200 && request.status < 300) { + // If successful + resolve(request.responseText); } else { - // Nothing - // startClock(); + // If failed + reject({ + status: request.status, + statusText: request.statusText + }); } - } - ourRequest.onerror = function() { - // Nothing -// startClock(); - } - console.log(JSON.stringify(data)); - ourRequest.send(JSON.stringify(data)); -}; - - -const getQuestion = (queNum) => { -// start = 0; - // startClock(); - let data = { - queNum : queNum - }; - sendRequest('POST','/question/',data); -}; - -function getQNum(){ - return qNo; + }; + // Setup our HTTP request + request.open(type || "GET", url, true); + // Add csrf token + request.setRequestHeader("X-CSRFToken", csrftoken); + // Send the request + request.send(JSON.stringify(data)); + }); + } -window.onresize = function(){ - if ((window.outerHeight - window.innerHeight) > 100) { - // console was opened (or screen was resized) - alert("Sorry!! you will be logged out since you didn't follow instructions"); - window.location.href="/logout" +function getQuestion(queNum){ + + codeMap.set(qNo, getCode()) + sendRequest('POST', '/question/', { queNum }).then( + function(response){ + response = JSON.parse(response); + let inpt = response['sampIn'].split(' '); + let inStr = ''; + for(let i = 0; i < inpt.length;i++) + { + inStr += inpt[i]; + inStr += '\n'; + } + let que = response['question'] + '

'+'Sample Input'+'
'+response['sampTCNum']+'
'+inStr+'

'+'Sample Output'+'
'+response['sampleOut']; + document.getElementsByClassName('qno')[0].innerHTML='Q. '+(queNum+1); + document.getElementsByClassName('left')[0].innerHTML=que; + qNo = response['qNo']; + document.getElementById('score').innerHTML = response['userScore']; + var s= document.getElementById("codeInput"); + s.value= codeMap.get(queNum) + } + ).catch( + function(error){ + increaseTime(); + console.error(error); } + ); } - - - - - - - - - - - - - -function getCookie(name) { - var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)'); - return v ? v[2] : null; -} function login() { - var csrf_token = getCookie('csrftoken'); - var ourRequest = new XMLHttpRequest(); - ourRequest.open("POST","login/", true); - ourRequest.setRequestHeader("X-CSRFToken", csrf_token); - ourRequest.setRequestHeader("Content-type", "application/json"); - ourRequest.onload = function() { - if (ourRequest.status >= 200 && ourRequest.status < 400) { - ; - } else { + sendRequest('POST', 'login/', '').then( + function(resp){ + console.log(resp); } - } - ourRequest.onerror = function() { - // Nothing - } - ourRequest.send(); -} - -window.onload = () => { - // startClock(); + ).catch( + function(error){ + console.error(error); + } + ); } -function showAbout() { - document.getElementsByClassName('about')[0].style.display = 'flex'; +function showInstructions() { + document.getElementsByClassName('instructions')[0].style.display = 'flex'; document.getElementsByClassName('backdrop')[0].style.display = 'block'; } -function closeAbout() { - document.getElementsByClassName('about')[0].style.display = 'none'; +function closeInstructions() { + document.getElementsByClassName('instructions')[0].style.display = 'none'; document.getElementsByClassName('backdrop')[0].style.display = 'none'; } document.addEventListener('DOMContentLoaded', function() { var elems = document.querySelectorAll('select'); - console.log('hikljhg'); -// var instances = M.FormSelect.init(elems, options); - }); - - // Or with jQuery - - $(document).ready(function(){ - $('select').formSelect(); - }); - +}); + $(document).delegate('#codeInput', 'keydown', function(e) { var keyCode = e.keyCode || e.which; @@ -295,56 +308,30 @@ document.addEventListener('DOMContentLoaded', function() { } }); +function sideNavInit(){ let hamburger = document.querySelector(".hamburger"); const title = document.querySelector('.title') -hamburger.onclick = function(e){ - e.preventDefault; - if(hamburger.classList.contains("active")){ - hamburger.classList.remove("active"); - hamburger.style.transform = 'translateX(0)'; - document.getElementById('sidenav').style.transform = 'translateX(-100%)'; - title.style.left = 'calc(3vh + 50px)' - }else{ - hamburger.classList.add("active"); - hamburger.style.transform = 'translateX(21vw)'; - document.getElementById('sidenav').style.transform = 'translateX(0)'; - title.style.left = '3vh' + // Side-nav event handler + hamburger.onclick = function(e) { + e.preventDefault; + if (hamburger.classList.contains("active")) { + hamburger.classList.remove("active"); + hamburger.style.transform = 'translateX(0)'; + document.getElementById('sidenav').style.transform = 'translateX(-100%)'; + title.style.left = 'calc(3vh + 50px)' + } + else { + hamburger.classList.add("active"); + hamburger.style.transform = 'translateX(21vw)'; + document.getElementById('sidenav').style.transform = 'translateX(0)'; + title.style.left = '3vh' + } } } -// function Submit() { - -// } - -// let start = 0; -// let timerInterval; -let timerCont = document.getElementById('timer'); -// function increaseTime() -// function startClock() { -// timerInterval = setInterval(function() { -// start++; -// if(start >= 60) { -// if(start%60>=10) { -// timerCont.innerHTML = "0" + Number(Math.floor(start/60)) + ':' + Number(start%60); -// } else { -// timerCont.innerHTML = "0" + Number(Math.floor(start/60)) + ':0' + Number(start%60); -// } -// } else if(start < 60 && start >= 10){ -// timerCont.innerHTML = '00:' + Number(start); -// } else if(start < 10) { -// timerCont.innerHTML = '00:0' + Number(start%60); -// } -// }, 1000); -// } - -// function stopClock() { -// clearInterval(timerInterval); -// } - -let s = 0, m = 0; function increaseTime() { - setInterval(function() { + timerId = setInterval(function() { if (s > 59){ s -= 60; m += 1; @@ -369,8 +356,84 @@ function increaseTime() { s++; }, 1000) +} +// Pause time function +function pauseTime() { + clearInterval(timerId); +} +// Won't allow user to cheat by changing text-color +let codeIntervalId; +let clicks = 0; +const hideCode = () => { + codeIntervalId = setInterval(() => document.getElementById('codeInput').style.color = 'black', 200); +} + +function increaseClicks(){ + pauseTime(); + let data = { + 'clicks' : clicks+1 + }; + sendRequest('POST', '/increaseClicks/', data).then( + function(response){ + increaseTime(); + } + ).catch( + function(error){ + increaseTime(); + console.error(error); + } + ); } -increaseTime() \ No newline at end of file +const showCode = () => { + pauseTime(); + sendRequest('GET', '/getChancesUsed/', null).then( + function(response){ + response = JSON.parse(response); + clicks = response['chancesUsed']; + const box = document.getElementById('codeInput'); + if (box.disabled === false) { + // Functionality won't be achieved after two clicks + if (clicks >= 2) { + // box.disabled = false; + // alert('You have used up your time!'); + Swal.fire( + 'Sorry..', + 'You have used up your time!', + 'error' + ); + return; + } + else { + // Disable button and show code for 5 seconds + box.disabled = true; + clearInterval(codeIntervalId); + box.style.color = 'white'; + setTimeout(() => { + hideCode() + box.disabled = false; + }, 5000); + } + increaseClicks(); + } + else{ + // alert('You have used up your time!'); + Swal.fire( + 'Sorry..', + 'You have used up your time!', + 'error' + ); + } + } + ).catch( + function(error){ + increaseTime(); + console.error(error); + } + ); +} +$(document).ready(function(){ + $('select').formSelect(); +}); \ No newline at end of file diff --git a/blind_coding/static/js/script.js b/blind_coding/static/js/script.js index e69de29..d8511be 100644 --- a/blind_coding/static/js/script.js +++ b/blind_coding/static/js/script.js @@ -0,0 +1,26 @@ +function getLeaderboard() { + $.ajax({ + url : "http://127.0.0.1:8000/leaderboard/", + type : "GET", + beforeSend : function() { + document.getElementById('leaderboard-loader').style.display = 'block'; + }, + success : function(jsondata) { + var objRecieved = jQuery.parseJSON(JSON.stringify(jsondata)); + let template = document.getElementById("leaderboard-row"); + document.getElementById('leaderboard-loader').style.display = 'none'; + for (var i = 0; i < objRecieved.username.length; ++i) { + let clone = template.content.cloneNode(true); + document.getElementById('leaderboard-body').appendChild(clone); + document.getElementsByClassName('rank')[i+2].innerHTML = i+1; //Get Array of Username's here + document.getElementsByClassName('name')[i+2].innerHTML = objRecieved.username[i]; //Get Array of Username's here + document.getElementsByClassName('score')[i+2].innerHTML = objRecieved.score[i]; //Get Array of Score's here + } + document.getElementById('userRank').innerHTML = 'Your Rank : ' + objRecieved.rank; + document.getElementById('myrank').innerHTML = objRecieved.rank; + }, + error : function() { + console.log("Error"); + } + }) +} \ No newline at end of file diff --git a/blind_coding/static/main/loggedIn.html b/blind_coding/static/main/loggedIn.html index 2ce878c..ee48f07 100644 --- a/blind_coding/static/main/loggedIn.html +++ b/blind_coding/static/main/loggedIn.html @@ -32,8 +32,8 @@
- - + +