Skip to content

Commit

Permalink
Update part1.md
Browse files Browse the repository at this point in the history
  • Loading branch information
waihongchung committed Jul 24, 2021
1 parent b60827e commit ba258d2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tutorials/part1.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ The entire 500 Cities dataset is over 200MB and contains 810,000 rows of data an

Next, we need to convert the dataset from the [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) format to a native JavaScript array. Fortunately, the DRESS Kit comes with a neat little function designed just for this purpose and it's conveniently named `DRESS.fromCSV`. We simply pass the `csv` variable to the function as a parameter and, voilà, out comes the dataset as an array of objects.

Afterward, we filter the array by selecting only rows that contain census tract level data and crude prevalence data. As we can see, one of the neat things that the `DRESS.fromCSV` does is converting each row of the CSV file into a separate JavasScript object. We can access each data point directly as a property of the object using the corresponding header as the property name, for instance `row.GeographicLevel`.
Afterward, we filter the array by selecting only rows that contain census tract-level data and crude prevalence data. As we can see, one of the neat things that the `DRESS.fromCSV` does is converting each row of the CSV file into a separate JavasScript object. We can access each data point directly as a property of the object using the corresponding header as the property name, for instance `row.GeographicLevel`.

3. As mentioned above, we would like to consider each census tract as a subject in our study. Ideally, we would like each subject to be represented by one object. Unfortunately, each of those 27 measures of chronic disease is recorded in a separate row in the dataset. We will need a way to combine these 27 measures for each census tract into one object. Such a task would be very difficult if we were to process the dataset in other prebuilt statistical software, but because we are working in a programmable environment, we can easily accomplish this with a few lines of code.
```javascript
Expand All @@ -140,7 +140,7 @@ The entire 500 Cities dataset is over 200MB and contains 810,000 rows of data an
```
Since we know that each census tract is identified by a unique identifier, we can use it to group related data points into one object. We also use this opportunity to discard those unnecessary columns. Next, we want to convert the numerical values, such as `PopulationCount` and `Data_Value` into numbers, which can easily be accomplished in JavaScript by prefixing the variables with a `+` sign. Finally, we want to save the array of newly created subjects to a file for future use. This can be accomplished easily using the `DRESS.save` function by passing the content and a file name as parameters.

4. If we run the code as is, it is like to cause a Long-Running Script error. Despite its efficiency, processing over 200MB of data using JavaScript is going to take a certain amount of time. To prevent the browser window from freezing up, we will take advantage of another cool little function named `DRESS.async`, which allows any functions within the DRESS Kit to be executed asynchronously. The function returns a [Promise](https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/promise), which will eventually resolve to the output of the asynchronously executed function. We can pass the Promise to another function called `DRESS.print`, which is used to display text on the HTML, in order to display a timer as the dataset is being processed.
4. If we run the code as is, it is likely to cause a Long-Running Script error. Despite its efficiency, processing over 200MB of data using JavaScript is going to take a certain amount of time. To prevent the browser window from freezing up, we will take advantage of another cool little function named `DRESS.async`, which allows any functions within the DRESS Kit to be executed asynchronously. The function returns a [Promise](https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/promise), which will eventually resolve to the output of the asynchronously executed function. We can pass the Promise to another function called `DRESS.print`, which is used to display text on the HTML, in order to display a timer as the dataset is being processed.

Here is the final code:
```javascript
Expand Down

0 comments on commit ba258d2

Please sign in to comment.