-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
435b5da
commit 5b7e995
Showing
18 changed files
with
8,077 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Contributing | ||
|
||
Contributions are welcomed! | ||
|
||
When contributing to this repository, please first discuss the change you wish to make via GitHub | ||
issue before making a change. This saves everyone from wasted effort in the event that the proposed | ||
changes need some adjustment before they are ready for submission. | ||
|
||
## Pull Request Process | ||
|
||
1. If your changes include multiple commits, please squash them into a single commit. Stack Overflow | ||
and various blogs can help with this process if you're not already familiar with it. | ||
2. Update the README.md where relevant. | ||
3. You may merge the Pull Request in once you have the sign-off of two other developers, or if you | ||
do not have permission to do that, you may request the second reviewer to merge it for you. | ||
|
||
## Contributor Code of Conduct | ||
|
||
As contributors and maintainers of this project, and in the interest of fostering an open and | ||
welcoming community, we pledge to respect all people who contribute through reporting issues, | ||
posting feature requests, updating documentation, submitting pull requests or patches, and other | ||
activities. | ||
|
||
We are committed to making participation in this project a harassment-free experience for everyone, | ||
regardless of level of experience, gender, gender identity and expression, sexual orientation, | ||
disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery | ||
* Personal attacks | ||
* Trolling or insulting/derogatory comments | ||
* Public or private harassment | ||
* Publishing other's private information, such as physical or electronic addresses, without explicit | ||
permission | ||
* Other unethical or unprofessional conduct. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, | ||
code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By | ||
adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently | ||
applying these principles to every aspect of managing this project. Project maintainers who do not | ||
follow or enforce the Code of Conduct may be permanently removed from the project team. | ||
|
||
This code of conduct applies both within project spaces and in public spaces when an individual is | ||
representing the project or its community. | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an | ||
issue or contacting one or more of the project maintainers. | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), | ||
version 1.2.0, available at | ||
[http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import pkg_resources | ||
__version__ = pkg_resources.require(__name__)[0].version | ||
del pkg_resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# License: This module is released under the terms of the LICENSE file | ||
# contained within this applications INSTALL directory | ||
|
||
""" | ||
__high_level_module_description_here__ | ||
""" | ||
|
||
# -- Coding Conventions | ||
# http://www.python.org/dev/peps/pep-0008/ - Use the Python style guide | ||
# http://sphinx.pocoo.org/rest.html - Use Restructured Text for docstrings | ||
|
||
# -- Public Imports | ||
import logging | ||
import pandas as pd | ||
import os | ||
import forecast | ||
import forecast_plot | ||
import argparse | ||
|
||
# -- Private Imports | ||
|
||
# -- Globals | ||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
# -- Exception classes | ||
|
||
|
||
# -- Functions | ||
def logger_info(msg, data): | ||
# Convenience function for easier log typing | ||
logger.info(msg + '\n%s', data) | ||
|
||
|
||
def run_forecast_app(path_in, path_out=None, forecast_years=2.0, | ||
col_name_y='y', col_name_weight='weight', | ||
col_name_x='x', col_name_date='date', | ||
col_name_source='source', | ||
include_all_fits=False | ||
): | ||
assert path_in is not None and os.path.exists(path_in), 'path_in needs to be a string pointing to a valid file path' | ||
assert not os.path.isdir(path_in) | ||
|
||
file_name = os.path.basename(path_in) | ||
file_name_p1 = file_name.split('.')[0] | ||
|
||
logger_info('file_name', file_name) | ||
logger_info('file_name p1', file_name_p1) | ||
|
||
if path_out is None: | ||
path_out = path_in | ||
assert os.path.exists(path_out) | ||
|
||
path_folder = os.path.dirname(path_out) | ||
|
||
logger_info('dir name', path_folder) | ||
|
||
path_data = os.path.join(path_folder, file_name_p1+'_fcast.csv') | ||
path_metadata = os.path.join(path_folder, file_name_p1+'_metadata.csv') | ||
path_plot = os.path.join(path_folder, file_name_p1 + '_fcast.png') | ||
|
||
logger_info('path_data', path_data) | ||
logger_info('path_metadata', path_metadata) | ||
logger_info('path_plot', path_plot) | ||
|
||
df_y = pd.read_csv(path_in) | ||
|
||
if col_name_date in df_y: # Need to parse date | ||
df_y[col_name_date] = df_y[col_name_date].pipe(pd.to_datetime) | ||
|
||
df_y = forecast.normalize_df(df_y, col_name_y, col_name_weight, col_name_x, col_name_date, | ||
col_name_source) | ||
|
||
dict_result = forecast.run_forecast(df_y, extrapolate_years=forecast_years, simplify_output=False, | ||
include_all_fits=include_all_fits) | ||
|
||
df_result = dict_result['data'] | ||
df_metadata = dict_result['metadata'] | ||
df_optimize_info = dict_result['optimize_info'] | ||
|
||
df_result.to_csv(path_data, index=False) | ||
df_metadata.to_csv(path_metadata, index=False) | ||
|
||
try: | ||
forecast_plot.plot_forecast_save(df_result, path_plot, width=1920, height=1080) | ||
except AssertionError: | ||
logger.info("Couldn't generate plot - R not installed") | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--path_in', help='Path of input .csv file') | ||
parser.add_argument('--path_out', help='Path of output folder - defaults to folder of path_in', default=None) | ||
parser.add_argument('--forecast_years', help='Years in forecast interval', default=2.0, type=float) | ||
parser.add_argument('--col_name_y', help='Name of column for y', default='y') | ||
parser.add_argument('--col_name_date', help='Name of column for date', default='date') | ||
parser.add_argument('--col_name_weight', help='Name of column for weight', default='weight') | ||
parser.add_argument('--col_name_source', help='Name of column for y', default='source') | ||
parser.add_argument('--col_name_x', help='Name of column for x', default='x') | ||
parser.add_argument('--include_all_fits', help='If true, output includes non-optimal models', action='store_true') | ||
|
||
args = parser.parse_args() | ||
logger.info('Input: path_in= %s', args.path_in) | ||
logger.info('Input: path_out= %s', args.path_out) | ||
logger.info('Input: col_name_y= %s', args.col_name_y) | ||
logger.info('Input: col_name_date= %s', args.col_name_date) | ||
logger.info('Input: col_name_x= %s', args.col_name_x) | ||
logger.info('Input: col_name_weight= %s', args.col_name_weight) | ||
logger.info('Input: col_name_source= %s', args.col_name_source) | ||
logger.info('Input: include_all_fits= %s', args.include_all_fits) | ||
|
||
run_forecast_app(args.path_in, args.path_out, args.forecast_years, | ||
args.col_name_y, args.col_name_weight, args.col_name_x, args.col_name_date, | ||
args.col_name_source, args.include_all_fits) | ||
|
||
# run_forecast_app('/Users/pec21/Downloads/file1.csv','/Users/pec21/Downloads/', | ||
# col_name_y='occup_erl', col_name_source='bend_name') | ||
|
||
|
||
# -- Main | ||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.