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

add-slv-wapper-and-stuff #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
163 changes: 163 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# 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
*.ipynb

# 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
Pipfile

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__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/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Ingenjörsarbete För Klimatet

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.
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
# co2-meal-planner
co2-meal-planner
<h1 align="center">ifk-co2-meal-planner</h1>

<p align="center">
<a href="https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner/actions/workflows/github-action-build.yaml">
<img src="https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner/actions/workflows/github-action-build.yaml/badge.svg?branch=main" alt="build" style="max-width: 100%;">
</a>
<a href="https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner/actions/workflows/github-action-build.yaml">
<img src="https://img.shields.io/endpoint?logo=github&labelColor=%23333a41&logoColor=%23959da5&url=https://gist.githubusercontent.com/mgcth//raw/ifk-co2-meal-planner-coverage-badge.json" alt="coverage" style="max-width: 100%;">
</a>
<a href="https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner/actions/workflows/github-action-docs.yaml">
<img src="https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner/actions/workflows/github-action-docs.yaml/badge.svg?branch=main" alt="docs" style="max-width: 100%;">
</a>
<a href="https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner/actions/workflows/github-action-lint.yaml">
<img src="https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner/actions/workflows/github-action-lint.yaml/badge.svg?branch=main" alt="lint" style="max-width: 100%;">
</a>
<a href="https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner/actions/workflows/github-action-type.yaml">
<img src="https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner/actions/workflows/github-action-type.yaml/badge.svg?branch=main" alt="type" style="max-width: 100%;">
</a>
</p>

<p align="center">
<a href="https://www.python.org">
<img src="https://img.shields.io/badge/Python-3.9%20|%203.10%20|%203.11%20|%203.12-blue" alt="Python: 3.9 - 3.12" style="max-width: 100%;">
</a>
<a href="https://pytest.org">
<img src="https://img.shields.io/badge/Testing_framework-pytest-a04000" alt="Testing framework: pytest" style="max-width: 100%;">
</a>
<a href="https://github.com/astral-sh/ruff">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Linter and formatter: ruff" style="max-width: 100%;">
</a>
<a href="http://mypy-lang.org">
<img src="https://img.shields.io/badge/Type_checker-mypy-1674b1" alt="Type checker: mypy" style="max-width: 100%;">
</a>
</p>

## Description

Welcome to ifk-co2-meal-planner.

## Configuration

When you start a new project, apart from the obvious changes,
there are some details to consider.

- Build workflow, follow the guide in [dynamic badges](https://github.com/Schneegans/dynamic-badges-action).
- To build docs, change `branch` in `github/workflows/github-action-docs.yaml`
from `["SET_TO_MAIN"]` to `["main"]`. You also need to activate Pages under repo
Settings/Pages.
Binary file added docs/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/ifk_logo_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/ifk_logo_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Welcome to ifk-co2-meal-planner

Docs for ifk-co2-meal-planner.
14 changes: 14 additions & 0 deletions material/partials/copyright.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{#-
This file was automatically generated - do not edit
-#}
<div class="md-copyright">
<div class="md-copyright__highlight">
<span>Made by <a href="https://ingenjorsarbeteforklimatet.se">Ingenjörsarbete för Klimatet</a></span>
</div>
{% if not config.extra.generator == false %}
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
{% endif %}
</div>
37 changes: 37 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
site_name: ifk-co2-meal-planner
repo_url: https://github.com/Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner
site_author: IFK
site_url: https://ingenjorsarbete-for-klimatet.github.io/ifk-co2-meal-planner/
repo_name: Ingenjorsarbete-For-Klimatet/ifk-co2-meal-planner

nav:
- Home: index.md

watch:
- src

theme:
name: material
custom_dir: material
palette:
scheme: default
primary: black
accent: light green
language: en
icon:
repo: fontawesome/brands/git-alt
logo: assets/ifk_logo_white.png
favicon: assets/favicon.png
features:
- navigation.tabs

plugins:
- search
- mkdocstrings

markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
78 changes: 78 additions & 0 deletions notebooks/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# %%
"""Example.

https://www.livsmedelsverket.se/om-oss/psidata/livsmedelsdatbasenalfa

ClimateHub have open source on CHG, but only free for internal use.
"""

import pandas as pd

# from IPython.display import display
from ifk_co2_meal_planner.rdi import rdi
from ifk_co2_meal_planner.slv_wrapper import SlvWrapper

slv = SlvWrapper()


# %%
slv.search_food("paranöt")

menu = {
"Mango": {"number": 574, "weight": 100},
"cashew": {"number": 1557, "weight": 65 / 4},
"hirs": {"number": 834, "weight": 1180.0 / 5},
"kikärtor": {"number": 3815, "weight": 250 / 4},
"basilika": {"number": 379, "weight": 3},
"apelsin": {"number": 551, "weight": 80},
}

slv.get_minerals_from_number(1568)


# %%

mineral_dict = slv.populate_mineral_dict(menu)
mineral_df = slv.mineral_dict_to_df(mineral_dict)
mineral_df = slv.convert_betakaroten_to_retinol(mineral_df)
print(mineral_df)

mineral_df = slv.calculate_minerals_for_weight(mineral_df)

print(mineral_df)

# calculate total
mineral_df.loc["total"] = mineral_df.sum()

# create an own class for rdi?
rdi_dict = slv.init_mineral_dict()
for gen in rdi["Zink, Zn"].keys():
for col in rdi_dict.keys():
if col in rdi.keys():
rdi_dict[col].append(rdi[col][gen])
elif col == "name":
rdi_dict["name"].append(gen)
else:
rdi_dict[col].append(None)

rdi_df = pd.DataFrame.from_dict(rdi_dict)
rdi_df.set_index("name", inplace=True)
mineral_df = pd.concat([mineral_df, rdi_df])

pd.set_option("display.max_columns", 500)
print(mineral_df)

# %%

for gen in rdi["Zink, Zn"].keys():
mineral_df.loc[gen + " percentage"] = rdi_per = (
mineral_df.loc["total"] / mineral_df.loc[gen] * 100
)

# ax = mineral_df['total'].plot.bar(rot=0)
rdi_per_labels = ["female percentage", "male percentage", "4-6 years percentage"]
ax = mineral_df.loc[rdi_per_labels].dropna(axis=1, how="all").transpose().plot.barh()
ax.legend(bbox_to_anchor=(1.42, 1))
ax.axvline(x=100)
ax.set_xlim([0, 100])
ax.grid()
Loading