I'm making the following initial assumptions as part of the exercise:
- We're always going to get one
TurnOffcommand at the beginning and one at the end of the sequence. - Whenever we find duplicate entries (i.e. same timestamp) we will only leave the last one (sorted by insertion order)
- For all other purposes, entries will be sorted by timestamp
- I'm currently not enforcing that the dimmer value doesn't go over 1.0 (per one of the examples)
- I'm currently not doing any rounding or trimming of decimals
EOFwill be triggered by Ctrl + D or some other equivalent command (and I'm handling that internally rather than requiring the<<EOFUnix syntax)
I'm assuming the following structure:
<timestamp> <command>
where
timestampis any positive integer numbercommandis one of:Delta <value>valuein turn is composed of:Sign: either+or-Number: an unsigned (because the sign is already included) float number
TurnOff- This takes no parameters and is implicitly equivalent to:
Delta 0.0
- This takes no parameters and is implicitly equivalent to:
Having said all of this, any input that doesn't follow this structure will be rejected as invalid.
I'm assuming that the formula for calculating the total energy used will be:
Consumption per period = <period_length> * <consumption_rate>
Total = <period1_consumption> + <period2_consumption> +... + <periodn_consumption>
where
-
period_lengthis a float expressed in hours, calculated as:period_end_timestamp-period_start_timestamp
-
consumption_rateis a float expressed in watts (and depends on the wattage of the light bulb being used)
$ energy-estimator
> 1544206562 TurnOff
> 1544206563 Delta +0.5
> 1544210163 TurnOff
> EOF
Estimated energy used: 2.5 Wh
$ energy-estimator
> 1544206562 TurnOff
> 1544206563 Delta +0.5
> 1544210163 Delta -0.25
> 1544211963 Delta +0.75
> 1544211963 Delta +0.75
> 1544213763 TurnOff
> EOF
Estimated energy used: 5.625 Wh
brew install pipenv(if not already installed)make install
energy-estimator
This is not a true, standalone executable (it needs to run within the context of the python env), but is simple enough for now.
We could also use pyinstaller to package an actual independent, executable file. (We'll see if we have time for that)
EDIT: I didn't get a chance to test this, but I think what I'm missing is:
pip install pyinstaller --dev
And then to actually create the executable (and this would eventually get included within the Makefile):
pyinstaller cli.py
But again, I didn't test this (didn't want to risk breaking stuff and spending lots of time on it)
- Install dev dependencies with
make dev - Run test scripts with
make qa