Skip to content

Commit 0483e53

Browse files
committed
Doc: Fix grammar in chartjs tutorial
1 parent 6b3c166 commit 0483e53

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

chartjs.md

+28-28
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ You can tell very powerful stories using data.
44

55
![ChartJS Demo](images/data_visualization/chartjs/data_stories.gif)
66

7-
Should you want to 'see' or understand deeply the data generated in your application, there are a handful of libraries that can help. One of them is ChartJS, the focus of this article. [ChartJs](https://www.chartjs.org/docs/latest/) is a free JavaScript library for creating charts in the browser (HTML-based charts). It is very easy to use, though basic understanding of JavaScript is required.
7+
Should you want to 'see' or understand deeply the data generated in your application, there are a handful of libraries that can help. One of them is ChartJS, the focus of this article. [ChartJs](https://www.chartjs.org/docs/latest/) is a free JavaScript library for creating charts in the browser (HTML-based charts). It is very easy to use, though a basic understanding of JavaScript is required.
88

99
## What We Will Do?
1010

1111
We will build a simple flask application for a class teacher to record the mean scores of all the subjects in a class throughout a 3-term year. Example data we will need may include the following:
1212

13-
* **Subjects**: Math, English, Science, History, and Computer Science
13+
* **Subjects**: Maths, English, Science, History, and Computer Science
1414
* **Mean Scores**: [70, 80, 90, 100, 95]
1515
* **Term**: [1, 2, 3]
1616

@@ -26,7 +26,7 @@ The completed application can be found in this [GitHub repository](https://githu
2626
4. [Enable user login](#enable-user-login)
2727
5. [Improve user experience](#improve-user-experience)
2828
6. [Display the mean scores of each subject per term](#display-the-mean-scores-of-each-subject-per-term)
29-
7. [Show meanscore chart](#show-meanscore-chart)
29+
7. [Show mean score chart](#show-mean-score-chart)
3030

3131
### Create a simple flask app
3232

@@ -35,9 +35,9 @@ I have already created a simple flask app for you. You can refer to it in [this
3535

3636
### Add web forms to the app
3737

38-
Flask provides the [wtf](https://flask-wtf.readthedocs.io/en/latest/) library for creating web forms. This library is helps create forms that are used to collect data from a user, in our case, it will be the classroom teacher. To create a form, we will need to:
38+
Flask provides the [wtf](https://flask-wtf.readthedocs.io/en/latest/) library for creating web forms. This library helps create forms that are used to collect data from a user, in our case, it will be the classroom teacher. To create a form, we will need to:
3939

40-
- Create a _forms_ module to define all the forms we will need (login, register and meanscore)
40+
- Create a _forms_ module to define all the forms we will need (login, register, and mean score)
4141
- Create templates for each form (login.html, register.html)
4242
- Create a _views_ module to render our forms
4343

@@ -78,12 +78,12 @@ class RegistrationForm(FlaskForm):
7878
submit = SubmitField('Register')
7979
```
8080

81-
Here, we want to capture a teacher's email, username and their password to protect their account. A few arguments are used to validate a teacher's credentials. For example:
81+
Here, we want to capture a teacher's email, username, and password to protect their account. A few arguments are used to validate a teacher's credentials. For example:
8282

8383
- `DataRequred` ensures that the field is not empty.
8484
- `Length` ensures that the field is at least 1 character long and at most 64 characters long.
8585
- `Email` ensures that the field has a valid email address.
86-
- `Regexp` ensures that the field only contains letters, numbers, dots or underscores.
86+
- `Regexp` ensures that the field only contains letters, numbers, dots, or underscores.
8787
- `EqualTo` ensures that the password fields match.
8888

8989
`Email()` requires that we install `email-validator`, so remember to do so in the terminal (`pip3 install email-validator`).
@@ -106,15 +106,15 @@ This variable will be sourced from the environment. In the event the variable do
106106

107107
### Add data to the app
108108

109-
Just like web forms, we will also use classes to create a database model to store a user's data. `flask-sqlalchemy`, a flask-friendly wrapper to SQLAlchemy, will translate the classes, objects and methods to tables and SQL. Intentionally, I will use the SQLite database since it does not require a server to run.
109+
Just like web forms, we will also use classes to create a database model to store a user's data. `flask-sqlalchemy`, a flask-friendly wrapper to SQLAlchemy, will translate the classes, objects, and methods to tables and SQL. Intentionally, I will use the SQLite database since it does not require a server to run.
110110

111111
To install Flask-SQLAlchemy, run:
112112

113113
```python
114114
(venv)$ pip3 install flask-sqlalchemy
115115
```
116116

117-
Every time we create a new model, we need apply those changes to our database. Same goes to when we update the structure/schema of our database. This action is called `migrating` the database. Database migrations are easily handled by `flask-migrate`.
117+
Every time we create a new model, we need to apply those changes to our database. The same goes for when we update the structure/schema of our database. This action is called `migrating` the database. Database migrations are easily handled by `flask-migrate`.
118118

119119
To install Flask-Migrate, run:
120120

@@ -185,7 +185,7 @@ class User(db.Model):
185185
return check_password_hash(self.password_hash, password)
186186
```
187187

188-
We have created three columns in our table. The columns will store every user's username, email and password. The `password_hash` column will store the hashed version of the user's password. This is an additional security measure to secure users' data in the event the database is compromised.
188+
We have created three columns in our table. The columns will store every user's username, email, and password. The `password_hash` column will store the hashed version of the user's password. This is an additional security measure to secure users' data in the event the database is compromised.
189189

190190
This is a new structure. We need to apply these changes and create a brand new database table. To do so, we will run the commands below:
191191

@@ -221,13 +221,13 @@ def register():
221221
return render_template('register.html', title='Register', form=form)
222222
```
223223

224-
We store a user's information in a variable called `user`. Of interest her is to note that we do not pass a user's password data into this variable. Instead, we hash the password using the helper function `set_password()` as seen in `models.py`. Thereafter, we add the user to the database.
224+
We store a user's information in a variable called `user`. Of interest, here is to note that we do not pass a user's password data into this variable. Instead, we hash the password using the helper function `set_password()` as seen in `models.py`. Thereafter, we add the user to the database.
225225

226226
### Enable user login
227227

228228
After a user has registered, we redirect them to the login page. This is a good way to ensure that the user has successfully registered. To add this functionality, we will need to add some login logic to the `login()` view functions.
229229

230-
User login in flask is easily handled by `flask-login` package. We need to first install it and then create an instance of it in the app.
230+
User login in Flask is easily handled by `flask-login` package. We need to first install it and then create an instance of it in the app.
231231

232232
```python
233233
(venv)$ pip3 install flask-login
@@ -242,7 +242,7 @@ User login in flask is easily handled by `flask-login` package. We need to first
242242
login = LoginManager()
243243
```
244244

245-
Since our database has no clue about user sessions, we need to modily it slightly.
245+
Since our database has no clue about user sessions, we need to modify it slightly.
246246

247247
`app/models.py: Modify the User table`
248248
```python
@@ -320,7 +320,7 @@ We will then update our _base.html_ template to include a conditional statement
320320

321321
A quick reload will reveal the state of a user. If the user is logged in, then the link will change to _logout_. Upon logout, the user will be redirected to the login page.
322322

323-
### Improve user experience
323+
### Improve the user experience
324324

325325
__Flash Message__
326326

@@ -378,7 +378,7 @@ def RegistrationForm(FlaskForm):
378378

379379
```
380380

381-
Every time a new user tries to user an already existing email address or username, we will raise a validation error and provide useful information as to why the registration process does not work.
381+
Every time a new user tries to use an already existing email address or username, we will raise a validation error and provide useful information as to why the registration process does not work.
382382

383383
![Ux registration](images/data_visualization/chartjs/ux_registration.png)
384384

@@ -416,7 +416,7 @@ class MeanScore(FlaskForm):
416416
submit = SubmitField('Submit')
417417
```
418418

419-
We will show this form in the index page. So, let us update the index template to include this form.
419+
We will show this form on the index page. So, let us update the index template to include this form.
420420

421421
`app/templates/index.html: Display Mean Score Per Term Form`
422422

@@ -439,7 +439,7 @@ We will show this form in the index page. So, let us update the index template t
439439

440440
We need to update the `index()` view function to accommodate this form.
441441

442-
`app/routes.py: Handling the meanscore form`
442+
`app/routes.py: Handling the mean score form`
443443

444444
```python
445445
from app.forms import MeanScore
@@ -454,7 +454,7 @@ def index():
454454
return render_template('index.html', form=form)
455455
```
456456

457-
The form should be on display in the index template after refreshing the page. To story the data, we need to create a MeanScore model. This model will store the following data: term, math, english, science, ict, and history.
457+
The form should be on display in the index template after refreshing the page. To store the data, we need to create a MeanScore model. This model will store the following data: term, math, english, science, ict, and history.
458458

459459
`app/models.py: MeanScore Model`
460460

@@ -475,14 +475,14 @@ class Meanscore(db.Model):
475475
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
476476
```
477477

478-
The _User_ and the _Meanscore_ tables are related by the _user_id_ column. This means that each user will have a list of meanscores. To apply the changes we need to once again run the commands below:
478+
The _User_ and the _Meanscore_ tables are related by the _user_id_ column. This means that each user will have a list of mean scores. To apply the changes we need to once again run the commands below:
479479

480480
```python
481-
(venv)$ flask db migrate -m 'meanscore table'
481+
(venv)$ flask db migrate -m 'mean score table'
482482
(venv)$ flask db upgrade
483483
```
484484

485-
Finally, we need to add a bit of logic on the form to ensure that the data is processed and stored in the new database.
485+
Finally, we need to add a bit of logic to the form to ensure that the data is processed and stored in the new database.
486486

487487
`app/routes.py: Meanscore Form Logic`
488488

@@ -538,9 +538,9 @@ To display the results, we will need to update the index template.
538538

539539
Every time new data is entered, the output will be updated.
540540

541-
### Show meanscore chart
541+
### Show mean score chart
542542

543-
A [quick overview of ChartJS](https://www.chartjs.org/docs/latest/) reveals that in order for us to use this library, we need to get the latest version. We will add the line below in our base template to get started.
543+
A [quick overview of ChartJS](https://www.chartjs.org/docs/latest/) reveals that for us to use this library, we need to get the latest version. We will add the line below in our base template to get started.
544544

545545
`app/templates/base.html: Add ChartJS`
546546

@@ -611,11 +611,11 @@ A simple chart can be created as follows:
611611
</script>
612612
```
613613

614-
The most important elements for our chart will be the label, and the datasets. The label will be the lesson meanscores in any given term, and the datasets will be the actual mean scores. You can get the graph as a bar chart, a line chart, a pie chart, or a radar chart. We will stick with the basic line chart.
614+
The most important elements for our chart will be the label and the datasets. The label will be the lesson mean scores in any given term, and the datasets will be the actual mean scores. You can get the graph as a bar chart, a line chart, a pie chart, or a radar chart. We will stick with the basic line chart.
615615

616-
As you can see, the values needed for the chart are primarily sourced from a list. We need to figure out a logic to get the data from the database and dislplay it in a simple list. This changes will be applied to the `index()` view function.
616+
As you can see, the values needed for the chart are primarily sourced from a list. We need to figure out the logic to get the data from the database and display it in a simple list. These changes will be applied to the `index()` view function.
617617

618-
`app/routes.py: List meanscores`
618+
`app/routes.py: List mean scores`
619619

620620
```python
621621
@app.route('/', methods=['GET', 'POST'])
@@ -647,7 +647,7 @@ def index():
647647
history=history)
648648
```
649649

650-
Here, I have looped through the results stored in the database as filled by a particular teacher. The `teacher.meanscores.all()` method returns a list of all the meanscores for a particular teacher. The result is subsequrently appended to relevant lists. This lists will then be used in the index template to display the results.
650+
Here, I have looped through the results stored in the database as filled by a particular teacher. The `teacher.meanscores.all()` method returns a list of all the mean scores for a particular teacher. The result is subsequently appended to relevant lists. These lists will then be used in the index template to display the results.
651651

652652
`app/templates/index.html: Display Mean Score Per Term`
653653

@@ -725,7 +725,7 @@ Here, I have looped through the results stored in the database as filled by a pa
725725
{% endblock %}
726726
```
727727

728-
Notice how I once again loop through individual meanscore lists to retrieve the data we want. Intentionally, we use several dictionaries in our dataset list to display all the meanscores in one graph. Background color and border color are used to differentiate the different datasets.
728+
Notice how I once again loop through individual mean score lists to retrieve the data we want. Intentionally, we use several dictionaries in our dataset list to display all the mean scores in one graph. Background color and border color are used to differentiate the different datasets.
729729

730730
![Final chartjs demo](images/data_visualization/chartjs/final_chartjs_demo.png)
731731

0 commit comments

Comments
 (0)