Skip to content

Commit d6571e4

Browse files
authored
Merge pull request snychka#5 from pluralsight-projects/module1
Module1
2 parents fc369ed + 0f1d194 commit d6571e4

File tree

6 files changed

+324
-35
lines changed

6 files changed

+324
-35
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [Status](#status)
55
- [Overview](#overview)
66
- [Installation](#installation)
7+
- [Verify Local Environment](#verify-local-environment)
78
- [Windows](#windows)
89
- [macOS](#macos)
910
- [About pip](#about-pip)
@@ -20,6 +21,8 @@ This project is design to be completed on [Pluralsight](https://pluralsight.com)
2021

2122
## Installation
2223

24+
### Verify Local Environment
25+
2326
### Windows
2427

2528
Open a command prompt or powershell and run the following commands, replacing 'project-root' with the path to the root folder of the project.
@@ -37,25 +40,29 @@ Open a terminal and run the following commands, replacing 'project-root' with th
3740

3841
```bash
3942
> cd 'project-root'
40-
$ python3 -m venv venv
41-
$ source venv/bin/activate
42-
$ pip install -r requirements.txt
43+
> python3 -m venv venv
44+
> source venv/bin/activate
45+
> pip install -r requirements.txt
4346
```
4447

4548
*Note: If you've installed Python 3 using a method other than Homebrew, you might need to type `python` in the second command instead of `python3`.*
4649

4750
### About pip
4851

49-
Versions pip updates frequently, but versions greater than 10.x.x should work with this project.
52+
`pip` updates frequently, but versions greater than 10.x.x should work with this project.
5053

5154
## Verify Setup
5255

5356
In order to verify that everything is setup correctly, run the following command from the project root.
5457

5558
```bash
56-
> pytest
59+
pytest
5760
```
5861

59-
You should see that all the tests are failing. This is good! We’ll be fixing these tests once we jump into the build step. Every time you want to check your work locally you can type that command, and it will report the status of every task in the project.
62+
You should see that all the tests are failing. This is good! We’ll be fixing these tests once we jump into the build step.
63+
64+
Every time you want to check your work locally you can type that command, and it will report the status of every task in the project.
6065

6166
## Previewing Your Work
67+
68+
You can preview your work by opening a terminal, changing to the project root, activating the virtual environment, and executing the appropriate python script. For example `python sensor/sensor.py`.

sensor/load_data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@
55

66
def load_sensor_data():
77
sensor_data = []
8+
9+
sensor_files = glob.glob(os.path.join(os.getcwd(), 'datasets', '*.csv'))
10+
11+
# Loop over list of files
12+
for sensor_file in sensor_files:
13+
with open(sensor_file ) as data_file:
14+
# Create a csv.DictReader
15+
data_reader = csv.DictReader(data_file, delimiter=',')
16+
# Loop over each row dictionary
17+
for row in data_reader:
18+
# Create a list of dictionaries
19+
sensor_data.append(row)
20+
return sensor_data

sensor/sensor.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

sensor/sensor_app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Runner script for all modules
2+
from load_data import load_sensor_data # module 2
3+
4+
data = load_sensor_data()
5+
# print(f"Loaded records {len(data)}")
6+
print("Loaded records {}".format(len(data)))

tasks.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- [Module 1: Load Sensor Data From Files](#module-1-load-sensor-data-from-files)
66
- [Task 1: Import os, glob, and csv](#task-1-import-os-glob-and-csv)
77
- [Task 2: Create a Function to parse the data](#task-2-create-a-function-to-parse-the-data)
8+
- [Task 3: Set Python File Management](#task-3-set-python-file-management)
9+
- [Task 4: Read CSV Files](#task-4-read-csv-files)
810
- [Module 2: Create a Class HomeData](#module-2-create-a-class-homedata)
911
- [Module 3: Analyze Temperature Data](#module-3-analyze-temperature-data)
1012
- [Module 4: Analyze Humidity Data](#module-4-analyze-humidity-data)
@@ -21,30 +23,32 @@ Draft.
2123

2224
[//]:# (@pytest.mark.test_load_data_function_module1)
2325

24-
```python
25-
import os
26-
import glob
27-
import csv
28-
```
29-
3026
The dataset for this project is stored in several CSV files found in the `dataset` folder. It represents the data collected from a device with multiple sensors. The records include measurements of temperature, humidity, energy consumption, and particle count in the air over a given area. The data is collected over a period of 24 hours.
3127

3228
To start, open the file called `load_data.py` in the `sensor` folder - the rest of the tasks in this module happen in this same file.
3329

3430
At the top of the file create three import statements for `os`, `glob`, and `csv`. These libraries will allow us to work with a collection of files.
3531

36-
### Task 2: Create a Function to parse the data
32+
### Task 2: Create a Function to parse the data
3733

3834
[//]:# (@pytest.mark.test_load_data_load_sensor_func_module1)
3935

40-
```python
41-
def load_sensor_data():
42-
# create a list to store data
43-
sensor_data = []
44-
```
45-
4636
Create a method called `load_sensor_data` that takes no arguments.
47-
In the body of the `load_sensor_data` function, create variable called `sensor_data` and set it as an empty `list`.
37+
In the body of the `load_sensor_data` function, create variable called `sensor_data` and set it as an empty `list` - the rest of the tasks in this module happen in this function.
38+
39+
### Task 3: Set Python File Management
40+
41+
[//]:# (@pytest.mark.test_load_data_sensor_files_module1)
42+
43+
Below the `sensor_data` variable create another variable called `sensor_files` that is set to a call to the `glob.glob()` function.
44+
45+
Pass `glob` function a single argument, a call to the `os.path.join()` function. In turn pass `os.path.join()` three arguments: `os.getcwd()`, `datasets`, and `*.csv`.
46+
47+
The `datasets` argument corresponds to the folder with your sensor data. The data files are in `csv` format. You may open them and explore the content of the records in them.
48+
49+
### Task 4: Read CSV Files
50+
51+
[//]:# (@pytest.mark.test_load_data_load_sensor_func_module1)
4852

4953
## Module 2: Create a Class HomeData
5054

0 commit comments

Comments
 (0)