Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kassidy Buslach Sharks #81

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,47 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Report</title>
<link href="./styles/index.css" rel="stylesheet" type="text/css">
<!-- <link rel="node_modules" href="./node_modules/axios/dist/axios.min.js" -->

</head>
<header>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Your HTML is semantic and clearly written. Nice job!

<h1 id="headline"> Weather Report</h1>
<h2 id="city"> Edmonds</h2>
</header>

<body>

<section class="info">
<section>
<label>City: <input type="text" id="input" value=" "></label>
<button id="enter">Enter</button>
<button type ="reset" id="reset">Reset</button>
</section>
<section id="temperatureContainer">
<button id="upButton"> Increase Temperature</button>
<h2 id="f"> Degrees Fahrenheit:60</h2>
<button id="downButton"> Decrease Temperature</button>
</section>
<section>
<select id="sky">
<option>Sunny</option>
<option>Cloudy</option>
<option>Rainy</option>
<option>Snowy</option>
</select>
<span id="skies">☁️ ☁️ ☁️ ☀️ ☁️ ☁️</span>
</section>
</section>
<footer class="seasons">
<h2>Landscape:
<span id="conditions"> 🌸☀️🌸☀️🌸☀️🌸☀️🌸☀️</span>
</h2>


</footer>
Comment on lines +39 to +45

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this part of the page is at the bottom of the screen when I view it in a browser, it might be more fitting to use a section tag here instead of a footer tag.

A footer typically contains information about the author of the section, copyright data or links to related documents:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer

<script src="./src/index.js"></script>
<script src="./node_modules/axios/dist/axios.min.js"></script>

</body>

</html>
142 changes: 142 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
const state = {
fahrenheit: 60,
city: 'Edmonds',
sky: 'Sunny',
};
let num = state.fahrenheit;
const tempUp = (event) => {
state.fahrenheit += 1;
tempChangeColor(state.fahrenheit);
weatherGarden();
const increase = document.getElementById('f');
increase.textContent = `Degrees Fahrenheit:${state.fahrenheit}`;
return increase.textContent;
};

const tempDown = (event) => {
state.fahrenheit--;
tempChangeColor(state.fahrenheit);
weatherGarden();
const decrease = document.getElementById('f');
decrease.textContent = `Degrees Fahrenheit:${state.fahrenheit}`;
return decrease.textContent;
Comment on lines +18 to +22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice lines 18-22 are almost identical to lines 9-13 above. You can put these 5 lines into a helper method like updateTempAndDisplay() and then call that helper method in the tempUp and tempDown methods.

};

const cityInput = (event) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name getCityWeather on line 30 is very descriptive because it tells me exactly what the method will do. The name cityInput is vague here. If you refactor this method from cityInput to updateCityInputAndGetRealWeather then you increase readability overall because someone could read the method name and know what the method will do.

let cityInput = document.getElementById('input').value;
state.city = cityInput;
let cityHeader = document.getElementById('city');
cityHeader.textContent = `${state.city}`;
getCityWeather();
};

const tempChangeColor = (num) => {
let element = document.getElementById('temperatureContainer');
if (state.fahrenheit >= 80) {
element.style.backgroundColor = 'red';
} else if (80 > state.fahrenheit && state.fahrenheit >= 70) {
element.style.backgroundColor = 'orange';
} else if (70 > state.fahrenheit && state.fahrenheit >= 60) {
element.style.backgroundColor = 'yellow';
} else if (60 > state.fahrenheit && state.fahrenheit >= 50) {
element.style.backgroundColor = 'green';
} else if (50 > state.fahrenheit && state.fahrenheit >= 33) {
element.style.backgroundColor = 'teal';
} else if (state.fahrenheit <= 32) {
element.style.backgroundColor = 'blue';
}
Comment on lines +34 to +47

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out the logic in tempChangeColor(), see how similar the branches are of the conditional statement. We look for whether the temperature is within a range, and pick a color accordingly. What if we had a list of records that we could iterate through to find the values. We could set up something like

const TEMP_COLORS = [ 
  { upperBound: 49, color: "teal"}, 
  { upperBound: 59, color: "green"}, 
  { upperBound: 69, color: "yellow"}, 
  { upperBound: 79, color: "orange"}, 
  { upperBound: 80, color: "red"}
];

Then your method would iterate through TEMP_COLORS and find the first record that has an upper bound higher than our temperature, then use it as the source of picking the color which would help make the function a bit more concise.

This could accommodate a scenario where you might have even more colors in the future, which would prevent your conditional statement from being a really long block of if/elif/elif and so on

};

const weatherGarden = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming the method name to something a little more descriptive like setWeatherGarden or updateWeatherGarden

let num = state.fahrenheit;
let conditions = document.getElementById('conditions');
if (num >= 80) {
conditions.textContent = '🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂';
} else if (80 > num && num >= 70) {
conditions.textContent = '🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷';
} else if (70 > num && num >= 60) {
conditions.textContent = '🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃';
} else if (60 > num && num >= 50) {
conditions.textContent = '🌲🌲🌲🍂🌲🍁🌲🌲🍂🌲🍂🍁🍂';
} else if (50 > num && num >= 33) {
conditions.textContent = '🍂🍁🍂🍂🍁🍂🍂🍁🍂🍂🍁🍂';
} else if (num < 32) {
conditions.textContent = '⛄️⛄️⛄️⛄️⛄️⛄️⛄️⛄️⛄️⛄️';
}
Comment on lines +51 to +65

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment from tempChangeColor() applies here too. You can use a constant variable that is a list of objects to iterate over the different weather garden options.

};

const getCityWeather = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice descriptive name

const q = state.city;
axios
.get('http://localhost:5000/location', { params: { q } })
.then((response) => {
console.log('success!', response.data);
console.log(response.data[0]['lat']);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to remove debugging print statements to keep your code from getting bloated and make it more readable

let lat = response.data[0]['lat'];
console.log(lat);
let lon = response.data[0]['lon'];
axios
.get('http://localhost:5000/weather', { params: { lat, lon } })
.then((response) => {
console.log('success!', response.data);
console.log(response.data['current']['temp']);
let degrees = response.data['current']['temp'];
let degreesF = (degrees - 273) * 1.8 + 32;
state.fahrenheit = parseInt(degreesF);
updateTemp();
Comment on lines +83 to +86

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting this logic in a helper method like formatAndUpdateTemp() to make the .then block more concise.

Line 84 could also go into its own helper method convertFromKelvin that could get called in formatAndUpdateTemp which you would ultimately call in this .then block

})
.catch((error) => {
console.log(error);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have an extra log statement here that can be removed since line 90 is already logging with more details

console.log('error!', error.response.data);
});
})
.catch((error) => {
console.log('error!', error);
});
};

const selectSky = (event) => {
const sky = document.getElementById('sky').value;
state.sky = sky;
const skies = document.getElementById('skies');
if (state.sky === 'Sunny') {
skies.textContent = '☁️ ☁️ ☁️ ☀️ ☁️ ☁️';
} else if (state.sky === 'Cloudy') {
skies.textContent = '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️';
} else if (state.sky === 'Rainy') {
skies.textContent = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧';
} else if (state.sky === 'Snowy') {
skies.textContent = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨';
}
};

const resetCity = (event) => {
const resetInput = document.getElementById('input');
resetInput.value = 'Edmonds';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a constant like DEFAULT_CITY for 'Edmonds' instead of using a string literal here. It's good practice to use constants when the literal value won't change and also if someone reads

cityInput.value = DEFAULT_CITY;

the intent is a little more clear.

cityInput();
state.fahrenheit = 60;
updateTemp();
};

const updateTemp = () => {
const update = document.getElementById('f');
update.textContent = `Degrees Fahrenheit:${state.fahrenheit}`;
};
const registerEventHandlers = (event) => {
const upButton = document.querySelector('#upButton');
upButton.addEventListener('click', tempUp);

const downButton = document.querySelector('#downButton');
downButton.addEventListener('click', tempDown);

const changeCity = document.getElementById('enter');
changeCity.addEventListener('click', cityInput);

selectSky();
const changeSky = document.getElementById('sky');
changeSky.addEventListener('change', selectSky);

const resetButton = document.getElementById('reset');
resetButton.addEventListener('click', resetCity);
};
document.addEventListener('DOMContentLoaded', registerEventHandlers);
Comment on lines +125 to +142

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

26 changes: 26 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
header {text-align: center;}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can change how this is formatted property and value on its own line (like what you did on lines 3-5) to be in line with the rest of the formatting in this file


ul {
list-style-type: none;
}
section.info {
Comment on lines +5 to +6

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a white space between a closing bracket and the start of the next rule

display: flex;
flex-direction: column;
justify-content: space-evenly;


Comment on lines +10 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete unnecessary whitespace here before the closing bracket to improve code readability

}
#temperatureContainer {
padding: 50px;
border-color: pink;
background-color: aquamarine;





Comment on lines +17 to +21

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete whitespace

}
footer {
display:flex;
justify-content: center;
}
141 changes: 141 additions & 0 deletions weather-report-proxy-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
.vscode
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
21 changes: 21 additions & 0 deletions weather-report-proxy-server/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Ada Project Repositories

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions weather-report-proxy-server/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn 'app:create_app()'
Loading