uccser/cs-field-guide

View on GitHub
csfieldguide/templates/interactives/shannon-experiment.html

Summary

Maintainability
Test Coverage
{% extends interactive_mode_template %}

{% load static i18n %}

{% block interactive_html %}
    <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal-title" aria-hidden="true" id="shannon-builder">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{% trans "Create your own experiment" %}</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <p>{% trans "Use this window to create a link to your own experiment." %}</p>

                    <div class="form-group">
                        <label for="builder-custom-sentences">Sentences</label>
                        <textarea class="form-control" id="builder-custom-sentences" rows="4"></textarea>
                        <small class="form-text text-muted">
                            {% trans "Enter each sentence on a new line." %}
                        </small>
                    </div>

                    <div class="form-group">
                        <label for="builder-custom-language">Default sentence language</label>
                        <select class="form-control" id="builder-custom-language"></select>
                        <small class="form-text text-muted">
                            {% trans "The interactive automatically adds any extra required characters." %}
                        </small>
                    </div>

                    <div class="form-group">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" value="" id="builder-show-statistics">
                            <label class="form-check-label" for="builder-show-statistics">
                                {% trans "Show statistics" %}
                            </label>
                            <small class="form-text text-muted">
                                {% trans "Open the statistics panel when loading the page." %}
                            </small>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" value="" id="builder-hide-builder">
                            <label class="form-check-label" for="builder-hide-builder">
                                {% trans "Hide builder" %}
                            </label>
                            <small class="form-text text-muted">
                                {% trans "Hide the button for this builder window." %}
                            </small>
                        </div>
                    </div>
                </div>
                <div id="builder-generated-link-container" class="modal-footer">
                    <p><small>Click the link below to access your custom experiment:</small></p>
                    <a class="mt-2" target="_blank" id="builder-generated-link"></a>
                </div>
            </div>
        </div>
    </div>

    <div id="shannon-experiment" class="container">
        <h1 class="h2">
            {% trans "Shannon's prediction and entropy of printed text experiment" %}
        </h1>

        <div id="shannon-language-picker">
            <label for="shannon-language-select">Text language:</label>
            <select name="shannon-language" id="shannon-language-select"></select>
        </div>
        <button id="new-sentence-button">New sentence</button>
        <p id="shannon-language-description"></p>

        <h2 class="h3">Available alphabet</h2>
        <p>Click the character you expect to be next in the sentence.</p>
        <p class="instruction-tip"><strong>Tip:</strong> The <span class="space-character">␣</span> character is used to represent the space character between words.</p>
        <div id="alphabet-buttons-container"></div>

        <h2 class="h3">Sentence</h2>
        <div id="sentence-container"></div>

        <button id="shannon-builder-button" type="button" data-toggle="modal" data-target="#shannon-builder">
            {% trans "Create your own experiment" %}
        </button>
        <button id="toggle-statistics-button">
            {% trans "Show statistics" %}
        </button>
        <div id="statistics-container">
            <h2 class="h3">Statistics</h2>
            <p><em>Statistics are updated after each correctly guessed character.</em></p>
            <div class="row">
                <div class="col-12 col-xl-6">
                    <h3 class="text-center">Guesses for each character</h3>
                    <canvas id="statistics-guess-per-character-chart" width="500" height="200"></canvas>
                </div>
                <div class="col-12 col-xl-6">
                    <h3 class="text-center">Guess totals</h3>
                    <canvas id="statistics-guess-counts-chart" width="500" height="200"></canvas>
                    <p class="text-center my-3">
                        For example: You have guessed
                        <span id="statistics-guess-counts-chart-example-value">0 characters</span>
                        on the 1st time.
                    </p>
                </div>
            </div>
            <div id="statistics-plaintext">
                <strong>Total guesses:</strong>
                <span id="statistic-total-guesses">?</span>
                <br>
                <strong>Approximate bound of bits per character:</strong>
                <span id="statistic-bit-bounds">?</span>
            </div>
        </div>
    </div>
{% endblock interactive_html %}

{% block interactive_css %}
    <link rel="stylesheet" href="{% static 'interactives/shannon-experiment/css/shannon-experiment.css' %}">
{% endblock interactive_css %}

{% block interactive_js %}
    <script type="text/javascript" src="{% static 'interactives/shannon-experiment/js/shannon-experiment.js' %}"></script>
{% endblock interactive_js %}