repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
j0057/github-release
github_release.py
_recursive_gh_get
def _recursive_gh_get(href, items): """Recursively get list of GitHub objects. See https://developer.github.com/v3/guides/traversing-with-pagination/ """ response = _request('GET', href) response.raise_for_status() items.extend(response.json()) if "link" not in response.headers: ret...
python
def _recursive_gh_get(href, items): """Recursively get list of GitHub objects. See https://developer.github.com/v3/guides/traversing-with-pagination/ """ response = _request('GET', href) response.raise_for_status() items.extend(response.json()) if "link" not in response.headers: ret...
[ "def", "_recursive_gh_get", "(", "href", ",", "items", ")", ":", "response", "=", "_request", "(", "'GET'", ",", "href", ")", "response", ".", "raise_for_status", "(", ")", "items", ".", "extend", "(", "response", ".", "json", "(", ")", ")", "if", "\"l...
Recursively get list of GitHub objects. See https://developer.github.com/v3/guides/traversing-with-pagination/
[ "Recursively", "get", "list", "of", "GitHub", "objects", "." ]
train
https://github.com/j0057/github-release/blob/5421d1ad3e49eaad50c800e548f889d55e159b9d/github_release.py#L148-L161
j0057/github-release
github_release.py
main
def main(github_token, github_api_url, progress): """A CLI to easily manage GitHub releases, assets and references.""" global progress_reporter_cls progress_reporter_cls.reportProgress = sys.stdout.isatty() and progress if progress_reporter_cls.reportProgress: progress_reporter_cls = _progress_b...
python
def main(github_token, github_api_url, progress): """A CLI to easily manage GitHub releases, assets and references.""" global progress_reporter_cls progress_reporter_cls.reportProgress = sys.stdout.isatty() and progress if progress_reporter_cls.reportProgress: progress_reporter_cls = _progress_b...
[ "def", "main", "(", "github_token", ",", "github_api_url", ",", "progress", ")", ":", "global", "progress_reporter_cls", "progress_reporter_cls", ".", "reportProgress", "=", "sys", ".", "stdout", ".", "isatty", "(", ")", "and", "progress", "if", "progress_reporter...
A CLI to easily manage GitHub releases, assets and references.
[ "A", "CLI", "to", "easily", "manage", "GitHub", "releases", "assets", "and", "references", "." ]
train
https://github.com/j0057/github-release/blob/5421d1ad3e49eaad50c800e548f889d55e159b9d/github_release.py#L180-L189
j0057/github-release
github_release.py
_update_release_sha
def _update_release_sha(repo_name, tag_name, new_release_sha, dry_run): """Update the commit associated with a given release tag. Since updating a tag commit is not directly possible, this function does the following steps: * set the release tag to ``<tag_name>-tmp`` and associate it with ``new_r...
python
def _update_release_sha(repo_name, tag_name, new_release_sha, dry_run): """Update the commit associated with a given release tag. Since updating a tag commit is not directly possible, this function does the following steps: * set the release tag to ``<tag_name>-tmp`` and associate it with ``new_r...
[ "def", "_update_release_sha", "(", "repo_name", ",", "tag_name", ",", "new_release_sha", ",", "dry_run", ")", ":", "if", "new_release_sha", "is", "None", ":", "return", "refs", "=", "get_refs", "(", "repo_name", ",", "tags", "=", "True", ",", "pattern", "=",...
Update the commit associated with a given release tag. Since updating a tag commit is not directly possible, this function does the following steps: * set the release tag to ``<tag_name>-tmp`` and associate it with ``new_release_sha``. * delete tag ``refs/tags/<tag_name>``. * update the relea...
[ "Update", "the", "commit", "associated", "with", "a", "given", "release", "tag", "." ]
train
https://github.com/j0057/github-release/blob/5421d1ad3e49eaad50c800e548f889d55e159b9d/github_release.py#L287-L343
lappis-unb/salic-ml
src/salicml/metrics/finance/approved_funds.py
approved_funds
def approved_funds(pronac, dt): """ Verifica se o valor total de um projeto é um outlier em relação aos projetos do mesmo seguimento cultural Dataframes: planilha_orcamentaria """ funds_df = data.approved_funds_by_projects project = ( funds_df .loc[funds_df['PRONAC'] == ...
python
def approved_funds(pronac, dt): """ Verifica se o valor total de um projeto é um outlier em relação aos projetos do mesmo seguimento cultural Dataframes: planilha_orcamentaria """ funds_df = data.approved_funds_by_projects project = ( funds_df .loc[funds_df['PRONAC'] == ...
[ "def", "approved_funds", "(", "pronac", ",", "dt", ")", ":", "funds_df", "=", "data", ".", "approved_funds_by_projects", "project", "=", "(", "funds_df", ".", "loc", "[", "funds_df", "[", "'PRONAC'", "]", "==", "pronac", "]", ")", "project", "=", "project"...
Verifica se o valor total de um projeto é um outlier em relação aos projetos do mesmo seguimento cultural Dataframes: planilha_orcamentaria
[ "Verifica", "se", "o", "valor", "total", "de", "um", "projeto", "é", "um", "outlier", "em", "relação", "aos", "projetos", "do", "mesmo", "seguimento", "cultural", "Dataframes", ":", "planilha_orcamentaria" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/approved_funds.py#L28-L58
lappis-unb/salic-ml
src/salicml_api/analysis/api.py
complexidade
def complexidade(obj): """ Returns a value that indicates project health, currently FinancialIndicator is used as this value, but it can be a result of calculation with other indicators in future """ indicators = obj.indicator_set.all() if not indicators: value = 0.0 else: ...
python
def complexidade(obj): """ Returns a value that indicates project health, currently FinancialIndicator is used as this value, but it can be a result of calculation with other indicators in future """ indicators = obj.indicator_set.all() if not indicators: value = 0.0 else: ...
[ "def", "complexidade", "(", "obj", ")", ":", "indicators", "=", "obj", ".", "indicator_set", ".", "all", "(", ")", "if", "not", "indicators", ":", "value", "=", "0.0", "else", ":", "value", "=", "indicators", ".", "first", "(", ")", ".", "value", "re...
Returns a value that indicates project health, currently FinancialIndicator is used as this value, but it can be a result of calculation with other indicators in future
[ "Returns", "a", "value", "that", "indicates", "project", "health", "currently", "FinancialIndicator", "is", "used", "as", "this", "value", "but", "it", "can", "be", "a", "result", "of", "calculation", "with", "other", "indicators", "in", "future" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml_api/analysis/api.py#L7-L18
lappis-unb/salic-ml
src/salicml_api/analysis/api.py
details
def details(project): """ Project detail endpoint, Returns project pronac, name, and indicators with details """ indicators = project.indicator_set.all() indicators_detail = [(indicator_details(i) for i in indicators)][0] if not indicators: indicators_det...
python
def details(project): """ Project detail endpoint, Returns project pronac, name, and indicators with details """ indicators = project.indicator_set.all() indicators_detail = [(indicator_details(i) for i in indicators)][0] if not indicators: indicators_det...
[ "def", "details", "(", "project", ")", ":", "indicators", "=", "project", ".", "indicator_set", ".", "all", "(", ")", "indicators_detail", "=", "[", "(", "indicator_details", "(", "i", ")", "for", "i", "in", "indicators", ")", "]", "[", "0", "]", "if",...
Project detail endpoint, Returns project pronac, name, and indicators with details
[ "Project", "detail", "endpoint", "Returns", "project", "pronac", "name", "and", "indicators", "with", "details" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml_api/analysis/api.py#L38-L57
lappis-unb/salic-ml
src/salicml_api/analysis/api.py
indicator_details
def indicator_details(indicator): """ Return a dictionary with all metrics in FinancialIndicator, if there aren't values for that Indicator, it is filled with default values """ metrics = format_metrics_json(indicator) metrics_list = set(indicator.metrics .filter(name__in...
python
def indicator_details(indicator): """ Return a dictionary with all metrics in FinancialIndicator, if there aren't values for that Indicator, it is filled with default values """ metrics = format_metrics_json(indicator) metrics_list = set(indicator.metrics .filter(name__in...
[ "def", "indicator_details", "(", "indicator", ")", ":", "metrics", "=", "format_metrics_json", "(", "indicator", ")", "metrics_list", "=", "set", "(", "indicator", ".", "metrics", ".", "filter", "(", "name__in", "=", "metrics_name_map", ".", "keys", "(", ")", ...
Return a dictionary with all metrics in FinancialIndicator, if there aren't values for that Indicator, it is filled with default values
[ "Return", "a", "dictionary", "with", "all", "metrics", "in", "FinancialIndicator", "if", "there", "aren", "t", "values", "for", "that", "Indicator", "it", "is", "filled", "with", "default", "values" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml_api/analysis/api.py#L60-L79
lappis-unb/salic-ml
src/salicml/data/query.py
Metrics.get_metric
def get_metric(self, pronac, metric): """ Get metric for the project with the given pronac number. Usage: >>> metrics.get_metric(pronac_id, 'finance.approved_funds') """ assert isinstance(metric, str) assert '.' in metric, 'metric must declare a namespace' ...
python
def get_metric(self, pronac, metric): """ Get metric for the project with the given pronac number. Usage: >>> metrics.get_metric(pronac_id, 'finance.approved_funds') """ assert isinstance(metric, str) assert '.' in metric, 'metric must declare a namespace' ...
[ "def", "get_metric", "(", "self", ",", "pronac", ",", "metric", ")", ":", "assert", "isinstance", "(", "metric", ",", "str", ")", "assert", "'.'", "in", "metric", ",", "'metric must declare a namespace'", "try", ":", "func", "=", "self", ".", "_metrics", "...
Get metric for the project with the given pronac number. Usage: >>> metrics.get_metric(pronac_id, 'finance.approved_funds')
[ "Get", "metric", "for", "the", "project", "with", "the", "given", "pronac", "number", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/data/query.py#L75-L90
lappis-unb/salic-ml
src/salicml/data/query.py
Metrics.register
def register(self, category): """ Usage: @metrics.register('finance') def approved_funds(pronac, data): return metric_from_data_and_pronac_number(data, pronac) """ def decorator(func): name = func.__name__ key = f'{category}...
python
def register(self, category): """ Usage: @metrics.register('finance') def approved_funds(pronac, data): return metric_from_data_and_pronac_number(data, pronac) """ def decorator(func): name = func.__name__ key = f'{category}...
[ "def", "register", "(", "self", ",", "category", ")", ":", "def", "decorator", "(", "func", ")", ":", "name", "=", "func", ".", "__name__", "key", "=", "f'{category}.{name}'", "self", ".", "_metrics", "[", "key", "]", "=", "func", "return", "func", "re...
Usage: @metrics.register('finance') def approved_funds(pronac, data): return metric_from_data_and_pronac_number(data, pronac)
[ "Usage", ":" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/data/query.py#L100-L112
lappis-unb/salic-ml
src/salicml_api/analysis/models/utils.py
execute_project_models_sql_scripts
def execute_project_models_sql_scripts(force_update=False): """ Used to get project information from MinC database and convert to this application Project models. Uses bulk_create if database is clean """ # TODO: Remove except and use ignore_conflicts # on bulk_create when django...
python
def execute_project_models_sql_scripts(force_update=False): """ Used to get project information from MinC database and convert to this application Project models. Uses bulk_create if database is clean """ # TODO: Remove except and use ignore_conflicts # on bulk_create when django...
[ "def", "execute_project_models_sql_scripts", "(", "force_update", "=", "False", ")", ":", "# TODO: Remove except and use ignore_conflicts", "# on bulk_create when django 2.2. is released", "with", "open", "(", "MODEL_FILE", ",", "\"r\"", ")", "as", "file_content", ":", "query...
Used to get project information from MinC database and convert to this application Project models. Uses bulk_create if database is clean
[ "Used", "to", "get", "project", "information", "from", "MinC", "database", "and", "convert", "to", "this", "application", "Project", "models", ".", "Uses", "bulk_create", "if", "database", "is", "clean" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml_api/analysis/models/utils.py#L20-L52
lappis-unb/salic-ml
src/salicml_api/analysis/models/utils.py
create_finance_metrics
def create_finance_metrics(metrics: list, pronacs: list): """ Creates metrics, creating an Indicator if it doesn't already exists Metrics are created for projects that are in pronacs and saved in database. args: metrics: list of names of metrics that will be calculated p...
python
def create_finance_metrics(metrics: list, pronacs: list): """ Creates metrics, creating an Indicator if it doesn't already exists Metrics are created for projects that are in pronacs and saved in database. args: metrics: list of names of metrics that will be calculated p...
[ "def", "create_finance_metrics", "(", "metrics", ":", "list", ",", "pronacs", ":", "list", ")", ":", "missing", "=", "missing_metrics", "(", "metrics", ",", "pronacs", ")", "print", "(", "f\"There are {len(missing)} missing metrics!\"", ")", "processors", "=", "mp...
Creates metrics, creating an Indicator if it doesn't already exists Metrics are created for projects that are in pronacs and saved in database. args: metrics: list of names of metrics that will be calculated pronacs: pronacs in dataset that is used to calculate those metrics
[ "Creates", "metrics", "creating", "an", "Indicator", "if", "it", "doesn", "t", "already", "exists", "Metrics", "are", "created", "for", "projects", "that", "are", "in", "pronacs", "and", "saved", "in", "database", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml_api/analysis/models/utils.py#L55-L93
lappis-unb/salic-ml
src/salicml/metrics/finance/total_receipts.py
total_receipts
def total_receipts(pronac, dt): """ This metric calculates the project total of receipts and compare it to projects in the same segment output: is_outlier: True if projects receipts is not compatible to others projects in the same segment total_receipts: a...
python
def total_receipts(pronac, dt): """ This metric calculates the project total of receipts and compare it to projects in the same segment output: is_outlier: True if projects receipts is not compatible to others projects in the same segment total_receipts: a...
[ "def", "total_receipts", "(", "pronac", ",", "dt", ")", ":", "dataframe", "=", "data", ".", "planilha_comprovacao", "project", "=", "dataframe", ".", "loc", "[", "dataframe", "[", "'PRONAC'", "]", "==", "pronac", "]", "segment_id", "=", "project", ".", "il...
This metric calculates the project total of receipts and compare it to projects in the same segment output: is_outlier: True if projects receipts is not compatible to others projects in the same segment total_receipts: absolute number of receipts maxim...
[ "This", "metric", "calculates", "the", "project", "total", "of", "receipts", "and", "compare", "it", "to", "projects", "in", "the", "same", "segment", "output", ":", "is_outlier", ":", "True", "if", "projects", "receipts", "is", "not", "compatible", "to", "o...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/total_receipts.py#L9-L36
lappis-unb/salic-ml
src/salicml_api/analysis/preload_data.py
load_project_metrics
def load_project_metrics(): """ Create project metrics for financial indicator Updates them if already exists """ all_metrics = FinancialIndicator.METRICS for key in all_metrics: df = getattr(data, key) pronac = 'PRONAC' if key == 'planilha_captacao': pronac =...
python
def load_project_metrics(): """ Create project metrics for financial indicator Updates them if already exists """ all_metrics = FinancialIndicator.METRICS for key in all_metrics: df = getattr(data, key) pronac = 'PRONAC' if key == 'planilha_captacao': pronac =...
[ "def", "load_project_metrics", "(", ")", ":", "all_metrics", "=", "FinancialIndicator", ".", "METRICS", "for", "key", "in", "all_metrics", ":", "df", "=", "getattr", "(", "data", ",", "key", ")", "pronac", "=", "'PRONAC'", "if", "key", "==", "'planilha_capta...
Create project metrics for financial indicator Updates them if already exists
[ "Create", "project", "metrics", "for", "financial", "indicator", "Updates", "them", "if", "already", "exists" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml_api/analysis/preload_data.py#L10-L22
lappis-unb/salic-ml
src/salicml/metrics/finance/new_providers.py
new_providers
def new_providers(pronac, dt): """ Return the percentage of providers of a project that are new to the providers database. """ info = data.providers_info df = info[info['PRONAC'] == pronac] providers_count = data.providers_count.to_dict()[0] new_providers = [] segment_id = None ...
python
def new_providers(pronac, dt): """ Return the percentage of providers of a project that are new to the providers database. """ info = data.providers_info df = info[info['PRONAC'] == pronac] providers_count = data.providers_count.to_dict()[0] new_providers = [] segment_id = None ...
[ "def", "new_providers", "(", "pronac", ",", "dt", ")", ":", "info", "=", "data", ".", "providers_info", "df", "=", "info", "[", "info", "[", "'PRONAC'", "]", "==", "pronac", "]", "providers_count", "=", "data", ".", "providers_count", ".", "to_dict", "("...
Return the percentage of providers of a project that are new to the providers database.
[ "Return", "the", "percentage", "of", "providers", "of", "a", "project", "that", "are", "new", "to", "the", "providers", "database", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/new_providers.py#L9-L62
lappis-unb/salic-ml
src/salicml/metrics/finance/new_providers.py
average_percentage_of_new_providers
def average_percentage_of_new_providers(providers_info, providers_count): """ Return the average percentage of new providers per segment and the average percentage of all projects. """ segments_percentages = {} all_projects_percentages = [] providers_count = providers_count.to_dict()[0] ...
python
def average_percentage_of_new_providers(providers_info, providers_count): """ Return the average percentage of new providers per segment and the average percentage of all projects. """ segments_percentages = {} all_projects_percentages = [] providers_count = providers_count.to_dict()[0] ...
[ "def", "average_percentage_of_new_providers", "(", "providers_info", ",", "providers_count", ")", ":", "segments_percentages", "=", "{", "}", "all_projects_percentages", "=", "[", "]", "providers_count", "=", "providers_count", ".", "to_dict", "(", ")", "[", "0", "]...
Return the average percentage of new providers per segment and the average percentage of all projects.
[ "Return", "the", "average", "percentage", "of", "new", "providers", "per", "segment", "and", "the", "average", "percentage", "of", "all", "projects", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/new_providers.py#L66-L97
lappis-unb/salic-ml
src/salicml/metrics/finance/new_providers.py
providers_count
def providers_count(df): """ Returns total occurrences of each provider in the database. """ providers_count = {} cnpj_array = df.values for a in cnpj_array: cnpj = a[0] occurrences = providers_count.get(cnpj, 0) providers_count[cnpj] = occurrences + 1 return pd...
python
def providers_count(df): """ Returns total occurrences of each provider in the database. """ providers_count = {} cnpj_array = df.values for a in cnpj_array: cnpj = a[0] occurrences = providers_count.get(cnpj, 0) providers_count[cnpj] = occurrences + 1 return pd...
[ "def", "providers_count", "(", "df", ")", ":", "providers_count", "=", "{", "}", "cnpj_array", "=", "df", ".", "values", "for", "a", "in", "cnpj_array", ":", "cnpj", "=", "a", "[", "0", "]", "occurrences", "=", "providers_count", ".", "get", "(", "cnpj...
Returns total occurrences of each provider in the database.
[ "Returns", "total", "occurrences", "of", "each", "provider", "in", "the", "database", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/new_providers.py#L101-L114
lappis-unb/salic-ml
src/salicml/metrics/finance/new_providers.py
all_providers_cnpj
def all_providers_cnpj(df): """ Return CPF/CNPJ of all providers in database. """ cnpj_list = [] for _, items in df.groupby('PRONAC'): unique_cnpjs = items['nrCNPJCPF'].unique() cnpj_list += list(unique_cnpjs) return pd.DataFrame(cnpj_list)
python
def all_providers_cnpj(df): """ Return CPF/CNPJ of all providers in database. """ cnpj_list = [] for _, items in df.groupby('PRONAC'): unique_cnpjs = items['nrCNPJCPF'].unique() cnpj_list += list(unique_cnpjs) return pd.DataFrame(cnpj_list)
[ "def", "all_providers_cnpj", "(", "df", ")", ":", "cnpj_list", "=", "[", "]", "for", "_", ",", "items", "in", "df", ".", "groupby", "(", "'PRONAC'", ")", ":", "unique_cnpjs", "=", "items", "[", "'nrCNPJCPF'", "]", ".", "unique", "(", ")", "cnpj_list", ...
Return CPF/CNPJ of all providers in database.
[ "Return", "CPF", "/", "CNPJ", "of", "all", "providers", "in", "database", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/new_providers.py#L132-L143
lappis-unb/salic-ml
src/salicml/metrics/finance/new_providers.py
get_providers_info
def get_providers_info(pronac): """ Return all info about providers of a project with the given pronac. """ df = data.providers_info grouped = df.groupby('PRONAC') return grouped.get_group(pronac)
python
def get_providers_info(pronac): """ Return all info about providers of a project with the given pronac. """ df = data.providers_info grouped = df.groupby('PRONAC') return grouped.get_group(pronac)
[ "def", "get_providers_info", "(", "pronac", ")", ":", "df", "=", "data", ".", "providers_info", "grouped", "=", "df", ".", "groupby", "(", "'PRONAC'", ")", "return", "grouped", ".", "get_group", "(", "pronac", ")" ]
Return all info about providers of a project with the given pronac.
[ "Return", "all", "info", "about", "providers", "of", "a", "project", "with", "the", "given", "pronac", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/new_providers.py#L146-L154
lappis-unb/salic-ml
src/salicml/metrics/base.py
get_info
def get_info(df, group, info=['mean', 'std']): """ Aggregate mean and std with the given group. """ agg = df.groupby(group).agg(info) agg.columns = agg.columns.droplevel(0) return agg
python
def get_info(df, group, info=['mean', 'std']): """ Aggregate mean and std with the given group. """ agg = df.groupby(group).agg(info) agg.columns = agg.columns.droplevel(0) return agg
[ "def", "get_info", "(", "df", ",", "group", ",", "info", "=", "[", "'mean'", ",", "'std'", "]", ")", ":", "agg", "=", "df", ".", "groupby", "(", "group", ")", ".", "agg", "(", "info", ")", "agg", ".", "columns", "=", "agg", ".", "columns", ".",...
Aggregate mean and std with the given group.
[ "Aggregate", "mean", "and", "std", "with", "the", "given", "group", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/base.py#L5-L11
lappis-unb/salic-ml
src/salicml/metrics/base.py
get_salic_url
def get_salic_url(item, prefix, df_values=None): """ Mount a salic url for the given item. """ url_keys = { 'pronac': 'idPronac', 'uf': 'uf', 'product': 'produto', 'county': 'idmunicipio', 'item_id': 'idPlanilhaItem', 'stage': 'etapa', } if df_val...
python
def get_salic_url(item, prefix, df_values=None): """ Mount a salic url for the given item. """ url_keys = { 'pronac': 'idPronac', 'uf': 'uf', 'product': 'produto', 'county': 'idmunicipio', 'item_id': 'idPlanilhaItem', 'stage': 'etapa', } if df_val...
[ "def", "get_salic_url", "(", "item", ",", "prefix", ",", "df_values", "=", "None", ")", ":", "url_keys", "=", "{", "'pronac'", ":", "'idPronac'", ",", "'uf'", ":", "'uf'", ",", "'product'", ":", "'produto'", ",", "'county'", ":", "'idmunicipio'", ",", "'...
Mount a salic url for the given item.
[ "Mount", "a", "salic", "url", "for", "the", "given", "item", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/base.py#L26-L59
lappis-unb/salic-ml
src/salicml/metrics/base.py
get_cpf_cnpj_by_pronac
def get_cpf_cnpj_by_pronac(pronac): """ Return the CNPF/CNPJ of the proponent of the project with the given pronac. """ df = data.planilha_projetos cpf_cnpj = None row_df = df[df['PRONAC'].astype(str) == str(pronac)] if not row_df.empty: cpf_cnpj = row_df.iloc[0]['CgcCpf'] ...
python
def get_cpf_cnpj_by_pronac(pronac): """ Return the CNPF/CNPJ of the proponent of the project with the given pronac. """ df = data.planilha_projetos cpf_cnpj = None row_df = df[df['PRONAC'].astype(str) == str(pronac)] if not row_df.empty: cpf_cnpj = row_df.iloc[0]['CgcCpf'] ...
[ "def", "get_cpf_cnpj_by_pronac", "(", "pronac", ")", ":", "df", "=", "data", ".", "planilha_projetos", "cpf_cnpj", "=", "None", "row_df", "=", "df", "[", "df", "[", "'PRONAC'", "]", ".", "astype", "(", "str", ")", "==", "str", "(", "pronac", ")", "]", ...
Return the CNPF/CNPJ of the proponent of the project with the given pronac.
[ "Return", "the", "CNPF", "/", "CNPJ", "of", "the", "proponent", "of", "the", "project", "with", "the", "given", "pronac", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/base.py#L62-L74
lappis-unb/salic-ml
src/salicml/metrics/base.py
has_receipt
def has_receipt(item): """ Verify if a item has a receipt. """ pronac_id = str(item['idPronac']) item_id = str(item["idPlanilhaItens"]) combined_id = f'{pronac_id}/{item_id}' return combined_id in data.receipt.index
python
def has_receipt(item): """ Verify if a item has a receipt. """ pronac_id = str(item['idPronac']) item_id = str(item["idPlanilhaItens"]) combined_id = f'{pronac_id}/{item_id}' return combined_id in data.receipt.index
[ "def", "has_receipt", "(", "item", ")", ":", "pronac_id", "=", "str", "(", "item", "[", "'idPronac'", "]", ")", "item_id", "=", "str", "(", "item", "[", "\"idPlanilhaItens\"", "]", ")", "combined_id", "=", "f'{pronac_id}/{item_id}'", "return", "combined_id", ...
Verify if a item has a receipt.
[ "Verify", "if", "a", "item", "has", "a", "receipt", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/base.py#L77-L86
lappis-unb/salic-ml
src/salicml/metrics/base.py
get_segment_projects
def get_segment_projects(segment_id): """ Returns all projects from a segment. """ df = data.all_items return ( df[df['idSegmento'] == str(segment_id)] .drop_duplicates(["PRONAC"]) .values )
python
def get_segment_projects(segment_id): """ Returns all projects from a segment. """ df = data.all_items return ( df[df['idSegmento'] == str(segment_id)] .drop_duplicates(["PRONAC"]) .values )
[ "def", "get_segment_projects", "(", "segment_id", ")", ":", "df", "=", "data", ".", "all_items", "return", "(", "df", "[", "df", "[", "'idSegmento'", "]", "==", "str", "(", "segment_id", ")", "]", ".", "drop_duplicates", "(", "[", "\"PRONAC\"", "]", ")",...
Returns all projects from a segment.
[ "Returns", "all", "projects", "from", "a", "segment", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/base.py#L90-L99
lappis-unb/salic-ml
src/salicml/metrics/base.py
receipt
def receipt(df): """ Return a dataframe to verify if a item has a receipt. """ mutated_df = df[['IdPRONAC', 'idPlanilhaItem']].astype(str) mutated_df['pronac_planilha_itens'] = ( f"{mutated_df['IdPRONAC']}/{mutated_df['idPlanilhaItem']}" ) return ( mutated_df .set_in...
python
def receipt(df): """ Return a dataframe to verify if a item has a receipt. """ mutated_df = df[['IdPRONAC', 'idPlanilhaItem']].astype(str) mutated_df['pronac_planilha_itens'] = ( f"{mutated_df['IdPRONAC']}/{mutated_df['idPlanilhaItem']}" ) return ( mutated_df .set_in...
[ "def", "receipt", "(", "df", ")", ":", "mutated_df", "=", "df", "[", "[", "'IdPRONAC'", ",", "'idPlanilhaItem'", "]", "]", ".", "astype", "(", "str", ")", "mutated_df", "[", "'pronac_planilha_itens'", "]", "=", "(", "f\"{mutated_df['IdPRONAC']}/{mutated_df['idPl...
Return a dataframe to verify if a item has a receipt.
[ "Return", "a", "dataframe", "to", "verify", "if", "a", "item", "has", "a", "receipt", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/base.py#L103-L115
lappis-unb/salic-ml
tasks.py
update_data
def update_data(ctx, models=True, pickles=False, f=False): """ Updates local django db projects and pickle files using salic database from MinC Pickles are saved in /data/raw/ from sql queries in /data/scripts/ Models are created from /data/scripts/models/ """ if pickles: save_sql_to...
python
def update_data(ctx, models=True, pickles=False, f=False): """ Updates local django db projects and pickle files using salic database from MinC Pickles are saved in /data/raw/ from sql queries in /data/scripts/ Models are created from /data/scripts/models/ """ if pickles: save_sql_to...
[ "def", "update_data", "(", "ctx", ",", "models", "=", "True", ",", "pickles", "=", "False", ",", "f", "=", "False", ")", ":", "if", "pickles", ":", "save_sql_to_files", "(", "f", ")", "if", "models", ":", "if", "f", ":", "manage", "(", "ctx", ",", ...
Updates local django db projects and pickle files using salic database from MinC Pickles are saved in /data/raw/ from sql queries in /data/scripts/ Models are created from /data/scripts/models/
[ "Updates", "local", "django", "db", "projects", "and", "pickle", "files", "using", "salic", "database", "from", "MinC", "Pickles", "are", "saved", "in", "/", "data", "/", "raw", "/", "from", "sql", "queries", "in", "/", "data", "/", "scripts", "/", "Mode...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/tasks.py#L72-L85
lappis-unb/salic-ml
tasks.py
update_models
def update_models(ctx, f=False): """ Updates local django db projects models using salic database from MinC """ if f: manage(ctx, 'create_models_from_sql --force True', env={}) else: manage(ctx, 'create_models_from_sql', env={})
python
def update_models(ctx, f=False): """ Updates local django db projects models using salic database from MinC """ if f: manage(ctx, 'create_models_from_sql --force True', env={}) else: manage(ctx, 'create_models_from_sql', env={})
[ "def", "update_models", "(", "ctx", ",", "f", "=", "False", ")", ":", "if", "f", ":", "manage", "(", "ctx", ",", "'create_models_from_sql --force True'", ",", "env", "=", "{", "}", ")", "else", ":", "manage", "(", "ctx", ",", "'create_models_from_sql'", ...
Updates local django db projects models using salic database from MinC
[ "Updates", "local", "django", "db", "projects", "models", "using", "salic", "database", "from", "MinC" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/tasks.py#L89-L97
lappis-unb/salic-ml
src/salicml_api/analysis/models/financial.py
FinancialIndicatorManager.create_indicator
def create_indicator(self, project, is_valid, metrics_list): """ Creates FinancialIndicator object for a project, calculating metrics and indicator value """ project = Project.objects.get(pronac=project) indicator, _ = (FinancialIndicator .objects....
python
def create_indicator(self, project, is_valid, metrics_list): """ Creates FinancialIndicator object for a project, calculating metrics and indicator value """ project = Project.objects.get(pronac=project) indicator, _ = (FinancialIndicator .objects....
[ "def", "create_indicator", "(", "self", ",", "project", ",", "is_valid", ",", "metrics_list", ")", ":", "project", "=", "Project", ".", "objects", ".", "get", "(", "pronac", "=", "project", ")", "indicator", ",", "_", "=", "(", "FinancialIndicator", ".", ...
Creates FinancialIndicator object for a project, calculating metrics and indicator value
[ "Creates", "FinancialIndicator", "object", "for", "a", "project", "calculating", "metrics", "and", "indicator", "value" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml_api/analysis/models/financial.py#L11-L28
lappis-unb/salic-ml
src/salicml/data/db_operations.py
save_sql_to_files
def save_sql_to_files(overwrite=False): """ Executes every .sql files in /data/scripts/ using salic db vpn and then saves pickle files into /data/raw/ """ ext_size = len(SQL_EXTENSION) path = DATA_PATH / 'scripts' save_dir = DATA_PATH / "raw" for file in os.listdir(path): if fil...
python
def save_sql_to_files(overwrite=False): """ Executes every .sql files in /data/scripts/ using salic db vpn and then saves pickle files into /data/raw/ """ ext_size = len(SQL_EXTENSION) path = DATA_PATH / 'scripts' save_dir = DATA_PATH / "raw" for file in os.listdir(path): if fil...
[ "def", "save_sql_to_files", "(", "overwrite", "=", "False", ")", ":", "ext_size", "=", "len", "(", "SQL_EXTENSION", ")", "path", "=", "DATA_PATH", "/", "'scripts'", "save_dir", "=", "DATA_PATH", "/", "\"raw\"", "for", "file", "in", "os", ".", "listdir", "(...
Executes every .sql files in /data/scripts/ using salic db vpn and then saves pickle files into /data/raw/
[ "Executes", "every", ".", "sql", "files", "in", "/", "data", "/", "scripts", "/", "using", "salic", "db", "vpn", "and", "then", "saves", "pickle", "files", "into", "/", "data", "/", "raw", "/" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/data/db_operations.py#L31-L49
lappis-unb/salic-ml
src/salicml_api/analysis/models/base.py
Indicator.fetch_weighted_complexity
def fetch_weighted_complexity(self, recalculate_metrics=False): """ Calculates indicator value according to metrics weights Uses metrics in database args: recalculate_metrics: If true metrics values are updated before using weights """...
python
def fetch_weighted_complexity(self, recalculate_metrics=False): """ Calculates indicator value according to metrics weights Uses metrics in database args: recalculate_metrics: If true metrics values are updated before using weights """...
[ "def", "fetch_weighted_complexity", "(", "self", ",", "recalculate_metrics", "=", "False", ")", ":", "# TODO: implment metrics recalculation", "max_total", "=", "sum", "(", "[", "self", ".", "metrics_weights", "[", "metric_name", "]", "for", "metric_name", "in", "se...
Calculates indicator value according to metrics weights Uses metrics in database args: recalculate_metrics: If true metrics values are updated before using weights
[ "Calculates", "indicator", "value", "according", "to", "metrics", "weights", "Uses", "metrics", "in", "database", "args", ":", "recalculate_metrics", ":", "If", "true", "metrics", "values", "are", "updated", "before", "using", "weights" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml_api/analysis/models/base.py#L27-L59
lappis-unb/salic-ml
src/salicml/metrics/finance/item_prices.py
item_prices
def item_prices(pronac, data): """ Verify if a project is an outlier compared to the other projects in his segment, based on the price of bought items. """ threshold = 0.1 outlier_info = get_outliers_percentage(pronac) outlier_info['is_outlier'] = outlier_info['percentage'] > threshold ...
python
def item_prices(pronac, data): """ Verify if a project is an outlier compared to the other projects in his segment, based on the price of bought items. """ threshold = 0.1 outlier_info = get_outliers_percentage(pronac) outlier_info['is_outlier'] = outlier_info['percentage'] > threshold ...
[ "def", "item_prices", "(", "pronac", ",", "data", ")", ":", "threshold", "=", "0.1", "outlier_info", "=", "get_outliers_percentage", "(", "pronac", ")", "outlier_info", "[", "'is_outlier'", "]", "=", "outlier_info", "[", "'percentage'", "]", ">", "threshold", ...
Verify if a project is an outlier compared to the other projects in his segment, based on the price of bought items.
[ "Verify", "if", "a", "project", "is", "an", "outlier", "compared", "to", "the", "other", "projects", "in", "his", "segment", "based", "on", "the", "price", "of", "bought", "items", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/item_prices.py#L12-L24
lappis-unb/salic-ml
src/salicml/metrics/finance/item_prices.py
is_outlier
def is_outlier(df, item_id, segment_id, price): """ Verify if a item is an outlier compared to the other occurrences of the same item, based on his price. Args: item_id: idPlanilhaItens segment_id: idSegmento price: VlUnitarioAprovado """ if (segment_id, item_id) not in...
python
def is_outlier(df, item_id, segment_id, price): """ Verify if a item is an outlier compared to the other occurrences of the same item, based on his price. Args: item_id: idPlanilhaItens segment_id: idSegmento price: VlUnitarioAprovado """ if (segment_id, item_id) not in...
[ "def", "is_outlier", "(", "df", ",", "item_id", ",", "segment_id", ",", "price", ")", ":", "if", "(", "segment_id", ",", "item_id", ")", "not", "in", "df", ".", "index", ":", "return", "False", "mean", "=", "df", ".", "loc", "[", "(", "segment_id", ...
Verify if a item is an outlier compared to the other occurrences of the same item, based on his price. Args: item_id: idPlanilhaItens segment_id: idSegmento price: VlUnitarioAprovado
[ "Verify", "if", "a", "item", "is", "an", "outlier", "compared", "to", "the", "other", "occurrences", "of", "the", "same", "item", "based", "on", "his", "price", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/item_prices.py#L27-L46
lappis-unb/salic-ml
src/salicml/metrics/finance/item_prices.py
aggregated_relevant_items
def aggregated_relevant_items(raw_df): """ Aggragation for calculate mean and std. """ df = ( raw_df[['idSegmento', 'idPlanilhaItens', 'VlUnitarioAprovado']] .groupby(by=['idSegmento', 'idPlanilhaItens']) .agg([np.mean, lambda x: np.std(x, ddof=0)]) ) df.columns = df.colu...
python
def aggregated_relevant_items(raw_df): """ Aggragation for calculate mean and std. """ df = ( raw_df[['idSegmento', 'idPlanilhaItens', 'VlUnitarioAprovado']] .groupby(by=['idSegmento', 'idPlanilhaItens']) .agg([np.mean, lambda x: np.std(x, ddof=0)]) ) df.columns = df.colu...
[ "def", "aggregated_relevant_items", "(", "raw_df", ")", ":", "df", "=", "(", "raw_df", "[", "[", "'idSegmento'", ",", "'idPlanilhaItens'", ",", "'VlUnitarioAprovado'", "]", "]", ".", "groupby", "(", "by", "=", "[", "'idSegmento'", ",", "'idPlanilhaItens'", "]"...
Aggragation for calculate mean and std.
[ "Aggragation", "for", "calculate", "mean", "and", "std", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/item_prices.py#L50-L63
lappis-unb/salic-ml
src/salicml/metrics/finance/item_prices.py
relevant_items
def relevant_items(df): """ Dataframe with items used by cultural projects, filtered by date and price. """ start_date = datetime(2013, 1, 1) df['DataProjeto'] = pd.to_datetime(df['DataProjeto']) # get only projects newer than start_date # and items with price > 0 df = df[df.DataPr...
python
def relevant_items(df): """ Dataframe with items used by cultural projects, filtered by date and price. """ start_date = datetime(2013, 1, 1) df['DataProjeto'] = pd.to_datetime(df['DataProjeto']) # get only projects newer than start_date # and items with price > 0 df = df[df.DataPr...
[ "def", "relevant_items", "(", "df", ")", ":", "start_date", "=", "datetime", "(", "2013", ",", "1", ",", "1", ")", "df", "[", "'DataProjeto'", "]", "=", "pd", ".", "to_datetime", "(", "df", "[", "'DataProjeto'", "]", ")", "# get only projects newer than st...
Dataframe with items used by cultural projects, filtered by date and price.
[ "Dataframe", "with", "items", "used", "by", "cultural", "projects", "filtered", "by", "date", "and", "price", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/item_prices.py#L67-L81
lappis-unb/salic-ml
src/salicml/metrics/finance/item_prices.py
items_with_price
def items_with_price(raw_df): """ Dataframe with price as number. """ df = ( raw_df [['PRONAC', 'idPlanilhaAprovacao', 'Item', 'idPlanilhaItens', 'VlUnitarioAprovado', 'idSegmento', 'DataProjeto', 'idPronac', 'UfItem', 'idProduto', 'cdCidade', 'cdEtapa...
python
def items_with_price(raw_df): """ Dataframe with price as number. """ df = ( raw_df [['PRONAC', 'idPlanilhaAprovacao', 'Item', 'idPlanilhaItens', 'VlUnitarioAprovado', 'idSegmento', 'DataProjeto', 'idPronac', 'UfItem', 'idProduto', 'cdCidade', 'cdEtapa...
[ "def", "items_with_price", "(", "raw_df", ")", ":", "df", "=", "(", "raw_df", "[", "[", "'PRONAC'", ",", "'idPlanilhaAprovacao'", ",", "'Item'", ",", "'idPlanilhaItens'", ",", "'VlUnitarioAprovado'", ",", "'idSegmento'", ",", "'DataProjeto'", ",", "'idPronac'", ...
Dataframe with price as number.
[ "Dataframe", "with", "price", "as", "number", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/item_prices.py#L85-L98
lappis-unb/salic-ml
src/salicml/metrics/finance/item_prices.py
get_outliers_percentage
def get_outliers_percentage(pronac): """ Returns the percentage of items of the project that are outliers. """ items = ( data.items_with_price .groupby(['PRONAC']) .get_group(pronac) ) df = data.aggregated_relevant_items outlier_items = {} url_prefix = '/pre...
python
def get_outliers_percentage(pronac): """ Returns the percentage of items of the project that are outliers. """ items = ( data.items_with_price .groupby(['PRONAC']) .get_group(pronac) ) df = data.aggregated_relevant_items outlier_items = {} url_prefix = '/pre...
[ "def", "get_outliers_percentage", "(", "pronac", ")", ":", "items", "=", "(", "data", ".", "items_with_price", ".", "groupby", "(", "[", "'PRONAC'", "]", ")", ".", "get_group", "(", "pronac", ")", ")", "df", "=", "data", ".", "aggregated_relevant_items", "...
Returns the percentage of items of the project that are outliers.
[ "Returns", "the", "percentage", "of", "items", "of", "the", "project", "that", "are", "outliers", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/item_prices.py#L101-L141
lappis-unb/salic-ml
src/salicml/metrics/finance/number_of_items.py
number_of_items
def number_of_items(pronac, dt): """ This metric calculates the project number of declared number of items and compare it to projects in the same segment output: is_outlier: True if projects number of items is not compatible to others projects in the same segment ...
python
def number_of_items(pronac, dt): """ This metric calculates the project number of declared number of items and compare it to projects in the same segment output: is_outlier: True if projects number of items is not compatible to others projects in the same segment ...
[ "def", "number_of_items", "(", "pronac", ",", "dt", ")", ":", "df", "=", "data", ".", "items_by_project", "project", "=", "df", ".", "loc", "[", "df", "[", "'PRONAC'", "]", "==", "pronac", "]", "seg", "=", "project", ".", "iloc", "[", "0", "]", "["...
This metric calculates the project number of declared number of items and compare it to projects in the same segment output: is_outlier: True if projects number of items is not compatible to others projects in the same segment valor: absolute number of items ...
[ "This", "metric", "calculates", "the", "project", "number", "of", "declared", "number", "of", "items", "and", "compare", "it", "to", "projects", "in", "the", "same", "segment", "output", ":", "is_outlier", ":", "True", "if", "projects", "number", "of", "item...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/number_of_items.py#L7-L31
lappis-unb/salic-ml
src/salicml/metrics/finance/common_items_ratio.py
common_items
def common_items(df): """ Returns the itens that are common in all the segments, in the format | idSegmento | id planilhaItens |. """ percentage = 0.1 return ( df .groupby(['idSegmento', 'idPlanilhaItens']) .count() .rename(columns={'PRONAC': 'itemOccurrences'}) ...
python
def common_items(df): """ Returns the itens that are common in all the segments, in the format | idSegmento | id planilhaItens |. """ percentage = 0.1 return ( df .groupby(['idSegmento', 'idPlanilhaItens']) .count() .rename(columns={'PRONAC': 'itemOccurrences'}) ...
[ "def", "common_items", "(", "df", ")", ":", "percentage", "=", "0.1", "return", "(", "df", ".", "groupby", "(", "[", "'idSegmento'", ",", "'idPlanilhaItens'", "]", ")", ".", "count", "(", ")", ".", "rename", "(", "columns", "=", "{", "'PRONAC'", ":", ...
Returns the itens that are common in all the segments, in the format | idSegmento | id planilhaItens |.
[ "Returns", "the", "itens", "that", "are", "common", "in", "all", "the", "segments", "in", "the", "format", "|", "idSegmento", "|", "id", "planilhaItens", "|", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/common_items_ratio.py#L14-L32
lappis-unb/salic-ml
src/salicml/metrics/finance/common_items_ratio.py
common_items_percentage
def common_items_percentage(pronac, seg_common_items): """ Returns the percentage of items in a project that are common in the cultural segment. """ if len(seg_common_items) == 0: return 0 project_items = get_project_items(pronac).values[:, 0] project_items_amount = len(project_item...
python
def common_items_percentage(pronac, seg_common_items): """ Returns the percentage of items in a project that are common in the cultural segment. """ if len(seg_common_items) == 0: return 0 project_items = get_project_items(pronac).values[:, 0] project_items_amount = len(project_item...
[ "def", "common_items_percentage", "(", "pronac", ",", "seg_common_items", ")", ":", "if", "len", "(", "seg_common_items", ")", "==", "0", ":", "return", "0", "project_items", "=", "get_project_items", "(", "pronac", ")", ".", "values", "[", ":", ",", "0", ...
Returns the percentage of items in a project that are common in the cultural segment.
[ "Returns", "the", "percentage", "of", "items", "in", "a", "project", "that", "are", "common", "in", "the", "cultural", "segment", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/common_items_ratio.py#L61-L79
lappis-unb/salic-ml
src/salicml/metrics/finance/common_items_ratio.py
common_items_metrics
def common_items_metrics(all_items, common_items): """ Calculates the percentage of common items for each project in each segment and calculates the mean and std of this percentage for each segment. """ segments = common_items.index.unique() metrics = {} for seg in segments: seg_...
python
def common_items_metrics(all_items, common_items): """ Calculates the percentage of common items for each project in each segment and calculates the mean and std of this percentage for each segment. """ segments = common_items.index.unique() metrics = {} for seg in segments: seg_...
[ "def", "common_items_metrics", "(", "all_items", ",", "common_items", ")", ":", "segments", "=", "common_items", ".", "index", ".", "unique", "(", ")", "metrics", "=", "{", "}", "for", "seg", "in", "segments", ":", "seg_common_items", "=", "segment_common_item...
Calculates the percentage of common items for each project in each segment and calculates the mean and std of this percentage for each segment.
[ "Calculates", "the", "percentage", "of", "common", "items", "for", "each", "project", "in", "each", "segment", "and", "calculates", "the", "mean", "and", "std", "of", "this", "percentage", "for", "each", "segment", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/common_items_ratio.py#L83-L106
lappis-unb/salic-ml
src/salicml/metrics/finance/common_items_ratio.py
get_project_items
def get_project_items(pronac): """ Returns all items from a project. """ df = data.all_items return ( df[df['PRONAC'] == pronac] .drop(columns=['PRONAC', 'idSegmento']) )
python
def get_project_items(pronac): """ Returns all items from a project. """ df = data.all_items return ( df[df['PRONAC'] == pronac] .drop(columns=['PRONAC', 'idSegmento']) )
[ "def", "get_project_items", "(", "pronac", ")", ":", "df", "=", "data", ".", "all_items", "return", "(", "df", "[", "df", "[", "'PRONAC'", "]", "==", "pronac", "]", ".", "drop", "(", "columns", "=", "[", "'PRONAC'", ",", "'idSegmento'", "]", ")", ")"...
Returns all items from a project.
[ "Returns", "all", "items", "from", "a", "project", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/common_items_ratio.py#L110-L118
lappis-unb/salic-ml
src/salicml/metrics/finance/common_items_ratio.py
segment_common_items
def segment_common_items(segment_id): """ Returns all the common items in a segment. """ df = data.common_items return ( df .loc[str(segment_id)] .reset_index(drop=1) .drop(columns=["itemOccurrences"]) )
python
def segment_common_items(segment_id): """ Returns all the common items in a segment. """ df = data.common_items return ( df .loc[str(segment_id)] .reset_index(drop=1) .drop(columns=["itemOccurrences"]) )
[ "def", "segment_common_items", "(", "segment_id", ")", ":", "df", "=", "data", ".", "common_items", "return", "(", "df", ".", "loc", "[", "str", "(", "segment_id", ")", "]", ".", "reset_index", "(", "drop", "=", "1", ")", ".", "drop", "(", "columns", ...
Returns all the common items in a segment.
[ "Returns", "all", "the", "common", "items", "in", "a", "segment", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/common_items_ratio.py#L122-L132
lappis-unb/salic-ml
src/salicml/metrics/finance/common_items_ratio.py
get_uncommon_items
def get_uncommon_items(pronac): """ Return all uncommon items of a project (related to segment common items). """ segment_id = get_segment_id(str(pronac)) seg_common_items = ( segment_common_items(segment_id) .set_index('idPlanilhaItens') .index ) project_items = ...
python
def get_uncommon_items(pronac): """ Return all uncommon items of a project (related to segment common items). """ segment_id = get_segment_id(str(pronac)) seg_common_items = ( segment_common_items(segment_id) .set_index('idPlanilhaItens') .index ) project_items = ...
[ "def", "get_uncommon_items", "(", "pronac", ")", ":", "segment_id", "=", "get_segment_id", "(", "str", "(", "pronac", ")", ")", "seg_common_items", "=", "(", "segment_common_items", "(", "segment_id", ")", ".", "set_index", "(", "'idPlanilhaItens'", ")", ".", ...
Return all uncommon items of a project (related to segment common items).
[ "Return", "all", "uncommon", "items", "of", "a", "project", "(", "related", "to", "segment", "common", "items", ")", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/common_items_ratio.py#L136-L159
lappis-unb/salic-ml
src/salicml/metrics/finance/common_items_ratio.py
add_info_to_uncommon_items
def add_info_to_uncommon_items(filtered_items, uncommon_items): """ Add extra info to the uncommon items. """ result = uncommon_items url_prefix = '/prestacao-contas/analisar/comprovante' for _, item in filtered_items.iterrows(): item_id = item['idPlanilhaItens'] item_name = un...
python
def add_info_to_uncommon_items(filtered_items, uncommon_items): """ Add extra info to the uncommon items. """ result = uncommon_items url_prefix = '/prestacao-contas/analisar/comprovante' for _, item in filtered_items.iterrows(): item_id = item['idPlanilhaItens'] item_name = un...
[ "def", "add_info_to_uncommon_items", "(", "filtered_items", ",", "uncommon_items", ")", ":", "result", "=", "uncommon_items", "url_prefix", "=", "'/prestacao-contas/analisar/comprovante'", "for", "_", ",", "item", "in", "filtered_items", ".", "iterrows", "(", ")", ":"...
Add extra info to the uncommon items.
[ "Add", "extra", "info", "to", "the", "uncommon", "items", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/common_items_ratio.py#L188-L206
lappis-unb/salic-ml
src/salicml/metrics/finance/common_items_ratio.py
common_items_ratio
def common_items_ratio(pronac, dt): """ Calculates the common items on projects in a cultural segment, calculates the uncommon items on projects in a cultural segment and verify if a project is an outlier compared to the other projects in his segment. """ segment_id = get_segment_id(str(pron...
python
def common_items_ratio(pronac, dt): """ Calculates the common items on projects in a cultural segment, calculates the uncommon items on projects in a cultural segment and verify if a project is an outlier compared to the other projects in his segment. """ segment_id = get_segment_id(str(pron...
[ "def", "common_items_ratio", "(", "pronac", ",", "dt", ")", ":", "segment_id", "=", "get_segment_id", "(", "str", "(", "pronac", ")", ")", "metrics", "=", "data", ".", "common_items_metrics", ".", "to_dict", "(", "orient", "=", "'index'", ")", "[", "segmen...
Calculates the common items on projects in a cultural segment, calculates the uncommon items on projects in a cultural segment and verify if a project is an outlier compared to the other projects in his segment.
[ "Calculates", "the", "common", "items", "on", "projects", "in", "a", "cultural", "segment", "calculates", "the", "uncommon", "items", "on", "projects", "in", "a", "cultural", "segment", "and", "verify", "if", "a", "project", "is", "an", "outlier", "compared", ...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/common_items_ratio.py#L210-L249
lappis-unb/salic-ml
src/salicml/metrics/finance/verified_funds.py
verified_funds
def verified_funds(pronac, dt): """ Responsable for detecting anomalies in projects total verified funds. """ dataframe = data.planilha_comprovacao project = dataframe.loc[dataframe['PRONAC'] == pronac] segment_id = project.iloc[0]["idSegmento"] pronac_funds = project[ ["idPlanilhaAp...
python
def verified_funds(pronac, dt): """ Responsable for detecting anomalies in projects total verified funds. """ dataframe = data.planilha_comprovacao project = dataframe.loc[dataframe['PRONAC'] == pronac] segment_id = project.iloc[0]["idSegmento"] pronac_funds = project[ ["idPlanilhaAp...
[ "def", "verified_funds", "(", "pronac", ",", "dt", ")", ":", "dataframe", "=", "data", ".", "planilha_comprovacao", "project", "=", "dataframe", ".", "loc", "[", "dataframe", "[", "'PRONAC'", "]", "==", "pronac", "]", "segment_id", "=", "project", ".", "il...
Responsable for detecting anomalies in projects total verified funds.
[ "Responsable", "for", "detecting", "anomalies", "in", "projects", "total", "verified", "funds", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/verified_funds.py#L9-L34
lappis-unb/salic-ml
src/salicml/metrics/finance/to_verify_funds.py
raised_funds_by_project
def raised_funds_by_project(df): """ Raised funds organized by project. """ df['CaptacaoReal'] = df['CaptacaoReal'].apply( pd.to_numeric ) return ( df[['Pronac', 'CaptacaoReal']] .groupby(['Pronac']) .sum() )
python
def raised_funds_by_project(df): """ Raised funds organized by project. """ df['CaptacaoReal'] = df['CaptacaoReal'].apply( pd.to_numeric ) return ( df[['Pronac', 'CaptacaoReal']] .groupby(['Pronac']) .sum() )
[ "def", "raised_funds_by_project", "(", "df", ")", ":", "df", "[", "'CaptacaoReal'", "]", "=", "df", "[", "'CaptacaoReal'", "]", ".", "apply", "(", "pd", ".", "to_numeric", ")", "return", "(", "df", "[", "[", "'Pronac'", ",", "'CaptacaoReal'", "]", "]", ...
Raised funds organized by project.
[ "Raised", "funds", "organized", "by", "project", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/to_verify_funds.py#L8-L19
lappis-unb/salic-ml
src/salicml/metrics/finance/to_verify_funds.py
to_verify_funds
def to_verify_funds(pronac, dt): """ Checks how much money is left for the project to verify, using raised_funds - verified_funds This value can be negative (a project can verify more money than the value approved) """ project_raised_funds = data.raised_funds_by_project.loc[pronac]['Captacao...
python
def to_verify_funds(pronac, dt): """ Checks how much money is left for the project to verify, using raised_funds - verified_funds This value can be negative (a project can verify more money than the value approved) """ project_raised_funds = data.raised_funds_by_project.loc[pronac]['Captacao...
[ "def", "to_verify_funds", "(", "pronac", ",", "dt", ")", ":", "project_raised_funds", "=", "data", ".", "raised_funds_by_project", ".", "loc", "[", "pronac", "]", "[", "'CaptacaoReal'", "]", "dataframe", "=", "data", ".", "planilha_comprovacao", "project_verified"...
Checks how much money is left for the project to verify, using raised_funds - verified_funds This value can be negative (a project can verify more money than the value approved)
[ "Checks", "how", "much", "money", "is", "left", "for", "the", "project", "to", "verify", "using", "raised_funds", "-", "verified_funds", "This", "value", "can", "be", "negative", "(", "a", "project", "can", "verify", "more", "money", "than", "the", "value", ...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/to_verify_funds.py#L23-L54
lappis-unb/salic-ml
src/salicml/metrics/finance/proponent_projects.py
proponent_projects
def proponent_projects(pronac, data): """ Checks the CNPJ/CPF of the proponent of project with the given pronac and returns all the projects that have been submitted by this proponent and all projects that have already been analyzed. """ cpf_cnpj = get_cpf_cnpj_by_pronac(pronac) propone...
python
def proponent_projects(pronac, data): """ Checks the CNPJ/CPF of the proponent of project with the given pronac and returns all the projects that have been submitted by this proponent and all projects that have already been analyzed. """ cpf_cnpj = get_cpf_cnpj_by_pronac(pronac) propone...
[ "def", "proponent_projects", "(", "pronac", ",", "data", ")", ":", "cpf_cnpj", "=", "get_cpf_cnpj_by_pronac", "(", "pronac", ")", "proponent_submitted_projects", "=", "{", "}", "proponent_analyzed_projects", "=", "{", "}", "if", "cpf_cnpj", ":", "submitted_projects"...
Checks the CNPJ/CPF of the proponent of project with the given pronac and returns all the projects that have been submitted by this proponent and all projects that have already been analyzed.
[ "Checks", "the", "CNPJ", "/", "CPF", "of", "the", "proponent", "of", "project", "with", "the", "given", "pronac", "and", "returns", "all", "the", "projects", "that", "have", "been", "submitted", "by", "this", "proponent", "and", "all", "projects", "that", ...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/proponent_projects.py#L9-L46
lappis-unb/salic-ml
src/salicml/metrics/finance/proponent_projects.py
analyzed_projects
def analyzed_projects(raw_df): """ Return all projects that was analyzed. """ df = raw_df[['PRONAC', 'proponenteCgcCpf']] analyzed_projects = df.groupby('proponenteCgcCpf')[ 'PRONAC' ].agg(['unique', 'nunique']) analyzed_projects.columns = ['pronac_list', 'num_pronacs'] return...
python
def analyzed_projects(raw_df): """ Return all projects that was analyzed. """ df = raw_df[['PRONAC', 'proponenteCgcCpf']] analyzed_projects = df.groupby('proponenteCgcCpf')[ 'PRONAC' ].agg(['unique', 'nunique']) analyzed_projects.columns = ['pronac_list', 'num_pronacs'] return...
[ "def", "analyzed_projects", "(", "raw_df", ")", ":", "df", "=", "raw_df", "[", "[", "'PRONAC'", ",", "'proponenteCgcCpf'", "]", "]", "analyzed_projects", "=", "df", ".", "groupby", "(", "'proponenteCgcCpf'", ")", "[", "'PRONAC'", "]", ".", "agg", "(", "[",...
Return all projects that was analyzed.
[ "Return", "all", "projects", "that", "was", "analyzed", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/proponent_projects.py#L50-L62
lappis-unb/salic-ml
src/salicml/metrics/finance/proponent_projects.py
submitted_projects
def submitted_projects(raw_df): """ Return all submitted projects. """ df = raw_df.astype({'PRONAC': str, 'CgcCpf': str}) submitted_projects = df.groupby('CgcCpf')[ 'PRONAC' ].agg(['unique', 'nunique']) submitted_projects.columns = ['pronac_list', 'num_pronacs'] return submitte...
python
def submitted_projects(raw_df): """ Return all submitted projects. """ df = raw_df.astype({'PRONAC': str, 'CgcCpf': str}) submitted_projects = df.groupby('CgcCpf')[ 'PRONAC' ].agg(['unique', 'nunique']) submitted_projects.columns = ['pronac_list', 'num_pronacs'] return submitte...
[ "def", "submitted_projects", "(", "raw_df", ")", ":", "df", "=", "raw_df", ".", "astype", "(", "{", "'PRONAC'", ":", "str", ",", "'CgcCpf'", ":", "str", "}", ")", "submitted_projects", "=", "df", ".", "groupby", "(", "'CgcCpf'", ")", "[", "'PRONAC'", "...
Return all submitted projects.
[ "Return", "all", "submitted", "projects", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/proponent_projects.py#L66-L77
lappis-unb/salic-ml
src/salicml/utils/read_csv.py
read_csv
def read_csv(csv_name, usecols=None): """Returns a DataFrame from a .csv file stored in /data/raw/""" csv_path = os.path.join(DATA_FOLDER, csv_name) csv = pd.read_csv(csv_path, low_memory=False, usecols=usecols, encoding="utf-8") return csv
python
def read_csv(csv_name, usecols=None): """Returns a DataFrame from a .csv file stored in /data/raw/""" csv_path = os.path.join(DATA_FOLDER, csv_name) csv = pd.read_csv(csv_path, low_memory=False, usecols=usecols, encoding="utf-8") return csv
[ "def", "read_csv", "(", "csv_name", ",", "usecols", "=", "None", ")", ":", "csv_path", "=", "os", ".", "path", ".", "join", "(", "DATA_FOLDER", ",", "csv_name", ")", "csv", "=", "pd", ".", "read_csv", "(", "csv_path", ",", "low_memory", "=", "False", ...
Returns a DataFrame from a .csv file stored in /data/raw/
[ "Returns", "a", "DataFrame", "from", "a", ".", "csv", "file", "stored", "in", "/", "data", "/", "raw", "/" ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/utils/read_csv.py#L10-L15
lappis-unb/salic-ml
src/salicml/utils/read_csv.py
read_csv_with_different_type
def read_csv_with_different_type(csv_name, column_types_dict, usecols=None): """Returns a DataFrame from a .csv file stored in /data/raw/. Reads the CSV as string. """ csv_path = os.path.join(DATA_FOLDER, csv_name) csv = pd.read_csv( csv_path, usecols=usecols, encoding="utf-8", ...
python
def read_csv_with_different_type(csv_name, column_types_dict, usecols=None): """Returns a DataFrame from a .csv file stored in /data/raw/. Reads the CSV as string. """ csv_path = os.path.join(DATA_FOLDER, csv_name) csv = pd.read_csv( csv_path, usecols=usecols, encoding="utf-8", ...
[ "def", "read_csv_with_different_type", "(", "csv_name", ",", "column_types_dict", ",", "usecols", "=", "None", ")", ":", "csv_path", "=", "os", ".", "path", ".", "join", "(", "DATA_FOLDER", ",", "csv_name", ")", "csv", "=", "pd", ".", "read_csv", "(", "csv...
Returns a DataFrame from a .csv file stored in /data/raw/. Reads the CSV as string.
[ "Returns", "a", "DataFrame", "from", "a", ".", "csv", "file", "stored", "in", "/", "data", "/", "raw", "/", ".", "Reads", "the", "CSV", "as", "string", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/utils/read_csv.py#L18-L34
lappis-unb/salic-ml
src/salicml/utils/read_csv.py
read_csv_as_integer
def read_csv_as_integer(csv_name, integer_columns, usecols=None): """Returns a DataFrame from a .csv file stored in /data/raw/. Converts columns specified by 'integer_columns' to integer. """ csv_path = os.path.join(DATA_FOLDER, csv_name) csv = pd.read_csv(csv_path, low_memory=False, usecols=usecols...
python
def read_csv_as_integer(csv_name, integer_columns, usecols=None): """Returns a DataFrame from a .csv file stored in /data/raw/. Converts columns specified by 'integer_columns' to integer. """ csv_path = os.path.join(DATA_FOLDER, csv_name) csv = pd.read_csv(csv_path, low_memory=False, usecols=usecols...
[ "def", "read_csv_as_integer", "(", "csv_name", ",", "integer_columns", ",", "usecols", "=", "None", ")", ":", "csv_path", "=", "os", ".", "path", ".", "join", "(", "DATA_FOLDER", ",", "csv_name", ")", "csv", "=", "pd", ".", "read_csv", "(", "csv_path", "...
Returns a DataFrame from a .csv file stored in /data/raw/. Converts columns specified by 'integer_columns' to integer.
[ "Returns", "a", "DataFrame", "from", "a", ".", "csv", "file", "stored", "in", "/", "data", "/", "raw", "/", ".", "Converts", "columns", "specified", "by", "integer_columns", "to", "integer", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/utils/read_csv.py#L37-L46
lappis-unb/salic-ml
src/salicml/metrics/finance/operation_code_receipts.py
check_receipts
def check_receipts(pronac, dt): """ Checks how many items are in a same receipt when payment type is check - is_outlier: True if there are any receipts that have more than one - itens_que_compartilham_comprovantes: List of items that share receipt """ df = verified_repeated_receipts_for_...
python
def check_receipts(pronac, dt): """ Checks how many items are in a same receipt when payment type is check - is_outlier: True if there are any receipts that have more than one - itens_que_compartilham_comprovantes: List of items that share receipt """ df = verified_repeated_receipts_for_...
[ "def", "check_receipts", "(", "pronac", ",", "dt", ")", ":", "df", "=", "verified_repeated_receipts_for_pronac", "(", "pronac", ")", "comprovantes_cheque", "=", "df", "[", "df", "[", "'tpFormaDePagamento'", "]", "==", "1.0", "]", "return", "metric_return", "(", ...
Checks how many items are in a same receipt when payment type is check - is_outlier: True if there are any receipts that have more than one - itens_que_compartilham_comprovantes: List of items that share receipt
[ "Checks", "how", "many", "items", "are", "in", "a", "same", "receipt", "when", "payment", "type", "is", "check", "-", "is_outlier", ":", "True", "if", "there", "are", "any", "receipts", "that", "have", "more", "than", "one", "-", "itens_que_compartilham_comp...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/operation_code_receipts.py#L19-L28
lappis-unb/salic-ml
src/salicml/metrics/finance/operation_code_receipts.py
transfer_receipts
def transfer_receipts(pronac, dt): """ Checks how many items are in a same receipt when payment type is bank transfer - is_outlier: True if there are any receipts that have more than one - itens_que_compartilham_comprovantes: List of items that share receipt """ df = verified_repeate...
python
def transfer_receipts(pronac, dt): """ Checks how many items are in a same receipt when payment type is bank transfer - is_outlier: True if there are any receipts that have more than one - itens_que_compartilham_comprovantes: List of items that share receipt """ df = verified_repeate...
[ "def", "transfer_receipts", "(", "pronac", ",", "dt", ")", ":", "df", "=", "verified_repeated_receipts_for_pronac", "(", "pronac", ")", "comprovantes_transferencia", "=", "df", "[", "df", "[", "'tpFormaDePagamento'", "]", "==", "2.0", "]", "return", "metric_return...
Checks how many items are in a same receipt when payment type is bank transfer - is_outlier: True if there are any receipts that have more than one - itens_que_compartilham_comprovantes: List of items that share receipt
[ "Checks", "how", "many", "items", "are", "in", "a", "same", "receipt", "when", "payment", "type", "is", "bank", "transfer", "-", "is_outlier", ":", "True", "if", "there", "are", "any", "receipts", "that", "have", "more", "than", "one", "-", "itens_que_comp...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/operation_code_receipts.py#L32-L42
lappis-unb/salic-ml
src/salicml/metrics/finance/operation_code_receipts.py
money_receipts
def money_receipts(pronac, dt): """ Checks how many items are in a same receipt when payment type is withdraw/money - is_outlier: True if there are any receipts that have more than one - itens_que_compartilham_comprovantes: List of items that share receipt """ df = verified_repeated_...
python
def money_receipts(pronac, dt): """ Checks how many items are in a same receipt when payment type is withdraw/money - is_outlier: True if there are any receipts that have more than one - itens_que_compartilham_comprovantes: List of items that share receipt """ df = verified_repeated_...
[ "def", "money_receipts", "(", "pronac", ",", "dt", ")", ":", "df", "=", "verified_repeated_receipts_for_pronac", "(", "pronac", ")", "comprovantes_saque", "=", "df", "[", "df", "[", "'tpFormaDePagamento'", "]", "==", "3.0", "]", "return", "metric_return", "(", ...
Checks how many items are in a same receipt when payment type is withdraw/money - is_outlier: True if there are any receipts that have more than one - itens_que_compartilham_comprovantes: List of items that share receipt
[ "Checks", "how", "many", "items", "are", "in", "a", "same", "receipt", "when", "payment", "type", "is", "withdraw", "/", "money", "-", "is_outlier", ":", "True", "if", "there", "are", "any", "receipts", "that", "have", "more", "than", "one", "-", "itens_...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/operation_code_receipts.py#L46-L56
lappis-unb/salic-ml
src/salicml/metrics/finance/raised_funds.py
raised_funds
def raised_funds(pronac, data): """ Returns the total raised funds of a project with the given pronac and if this project is an outlier based on this value. """ is_outlier, mean, std, total_raised_funds = get_outlier_info(pronac) maximum_expected_funds = gaussian_outlier.maximum_expected_val...
python
def raised_funds(pronac, data): """ Returns the total raised funds of a project with the given pronac and if this project is an outlier based on this value. """ is_outlier, mean, std, total_raised_funds = get_outlier_info(pronac) maximum_expected_funds = gaussian_outlier.maximum_expected_val...
[ "def", "raised_funds", "(", "pronac", ",", "data", ")", ":", "is_outlier", ",", "mean", ",", "std", ",", "total_raised_funds", "=", "get_outlier_info", "(", "pronac", ")", "maximum_expected_funds", "=", "gaussian_outlier", ".", "maximum_expected_value", "(", "mean...
Returns the total raised funds of a project with the given pronac and if this project is an outlier based on this value.
[ "Returns", "the", "total", "raised", "funds", "of", "a", "project", "with", "the", "given", "pronac", "and", "if", "this", "project", "is", "an", "outlier", "based", "on", "this", "value", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/raised_funds.py#L9-L22
lappis-unb/salic-ml
src/salicml/metrics/finance/raised_funds.py
segment_raised_funds_average
def segment_raised_funds_average(df): """ Return some info about raised funds. """ grouped = df.groupby('Segmento') aggregated = grouped.agg(['mean', 'std']) aggregated.columns = aggregated.columns.droplevel(0) return aggregated
python
def segment_raised_funds_average(df): """ Return some info about raised funds. """ grouped = df.groupby('Segmento') aggregated = grouped.agg(['mean', 'std']) aggregated.columns = aggregated.columns.droplevel(0) return aggregated
[ "def", "segment_raised_funds_average", "(", "df", ")", ":", "grouped", "=", "df", ".", "groupby", "(", "'Segmento'", ")", "aggregated", "=", "grouped", ".", "agg", "(", "[", "'mean'", ",", "'std'", "]", ")", "aggregated", ".", "columns", "=", "aggregated",...
Return some info about raised funds.
[ "Return", "some", "info", "about", "raised", "funds", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/raised_funds.py#L38-L46
lappis-unb/salic-ml
src/salicml/metrics/finance/raised_funds.py
get_outlier_info
def get_outlier_info(pronac): """ Return if a project with the given pronac is an outlier based on raised funds. """ df = data.planilha_captacao raised_funds_averages = data.segment_raised_funds_average.to_dict('index') segment_id = df[df['Pronac'] == pronac]['Segmento'].iloc[0] mean =...
python
def get_outlier_info(pronac): """ Return if a project with the given pronac is an outlier based on raised funds. """ df = data.planilha_captacao raised_funds_averages = data.segment_raised_funds_average.to_dict('index') segment_id = df[df['Pronac'] == pronac]['Segmento'].iloc[0] mean =...
[ "def", "get_outlier_info", "(", "pronac", ")", ":", "df", "=", "data", ".", "planilha_captacao", "raised_funds_averages", "=", "data", ".", "segment_raised_funds_average", ".", "to_dict", "(", "'index'", ")", "segment_id", "=", "df", "[", "df", "[", "'Pronac'", ...
Return if a project with the given pronac is an outlier based on raised funds.
[ "Return", "if", "a", "project", "with", "the", "given", "pronac", "is", "an", "outlier", "based", "on", "raised", "funds", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/raised_funds.py#L49-L66
lappis-unb/salic-ml
src/salicml/metrics/finance/verified_approved.py
verified_approved
def verified_approved(pronac, dt): """ This metric compare budgetary items of SALIC projects in terms of verified versus approved value Items that have vlComprovacao > vlAprovacao * 1.5 are considered outliers output: is_outlier: True if any item is outlier valor: Absolute nu...
python
def verified_approved(pronac, dt): """ This metric compare budgetary items of SALIC projects in terms of verified versus approved value Items that have vlComprovacao > vlAprovacao * 1.5 are considered outliers output: is_outlier: True if any item is outlier valor: Absolute nu...
[ "def", "verified_approved", "(", "pronac", ",", "dt", ")", ":", "items_df", "=", "data", ".", "approved_verified_items", "items_df", "=", "items_df", ".", "loc", "[", "items_df", "[", "'PRONAC'", "]", "==", "pronac", "]", "items_df", "[", "[", "APPROVED_COLU...
This metric compare budgetary items of SALIC projects in terms of verified versus approved value Items that have vlComprovacao > vlAprovacao * 1.5 are considered outliers output: is_outlier: True if any item is outlier valor: Absolute number of items that are outliers out...
[ "This", "metric", "compare", "budgetary", "items", "of", "SALIC", "projects", "in", "terms", "of", "verified", "versus", "approved", "value", "Items", "that", "have", "vlComprovacao", ">", "vlAprovacao", "*", "1", ".", "5", "are", "considered", "outliers", "ou...
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/metrics/finance/verified_approved.py#L12-L49
lappis-unb/salic-ml
src/salicml/data/loader.py
csv_to_pickle
def csv_to_pickle(path=ROOT / "raw", clean=False): """Convert all CSV files in path to pickle.""" for file in os.listdir(path): base, ext = os.path.splitext(file) if ext != ".csv": continue LOG(f"converting {file} to pickle") df = pd.read_csv(path / file, low_memory...
python
def csv_to_pickle(path=ROOT / "raw", clean=False): """Convert all CSV files in path to pickle.""" for file in os.listdir(path): base, ext = os.path.splitext(file) if ext != ".csv": continue LOG(f"converting {file} to pickle") df = pd.read_csv(path / file, low_memory...
[ "def", "csv_to_pickle", "(", "path", "=", "ROOT", "/", "\"raw\"", ",", "clean", "=", "False", ")", ":", "for", "file", "in", "os", ".", "listdir", "(", "path", ")", ":", "base", ",", "ext", "=", "os", ".", "path", ".", "splitext", "(", "file", ")...
Convert all CSV files in path to pickle.
[ "Convert", "all", "CSV", "files", "in", "path", "to", "pickle", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/data/loader.py#L105-L118
lappis-unb/salic-ml
src/salicml/data/loader.py
Loader.store
def store(self, loc, df): """Store dataframe in the given location. Store some arbitrary dataframe: >>> data.store('my_data', df) Now recover it from the global store. >>> data.my_data ... """ path = "%s.%s" % (self._root / "processed" / loc, FILE_EXTE...
python
def store(self, loc, df): """Store dataframe in the given location. Store some arbitrary dataframe: >>> data.store('my_data', df) Now recover it from the global store. >>> data.my_data ... """ path = "%s.%s" % (self._root / "processed" / loc, FILE_EXTE...
[ "def", "store", "(", "self", ",", "loc", ",", "df", ")", ":", "path", "=", "\"%s.%s\"", "%", "(", "self", ".", "_root", "/", "\"processed\"", "/", "loc", ",", "FILE_EXTENSION", ")", "WRITE_DF", "(", "df", ",", "path", ",", "*", "*", "WRITE_DF_OPTS", ...
Store dataframe in the given location. Store some arbitrary dataframe: >>> data.store('my_data', df) Now recover it from the global store. >>> data.my_data ...
[ "Store", "dataframe", "in", "the", "given", "location", "." ]
train
https://github.com/lappis-unb/salic-ml/blob/1b3ebc4f8067740999897ccffd9892dc94482a93/src/salicml/data/loader.py#L52-L66
MisterY/asset-allocation
asset_allocation/stocks.py
StocksInfo.close_databases
def close_databases(self): """ Close all database sessions """ if self.gc_book: self.gc_book.close() if self.pricedb_session: self.pricedb_session.close()
python
def close_databases(self): """ Close all database sessions """ if self.gc_book: self.gc_book.close() if self.pricedb_session: self.pricedb_session.close()
[ "def", "close_databases", "(", "self", ")", ":", "if", "self", ".", "gc_book", ":", "self", ".", "gc_book", ".", "close", "(", ")", "if", "self", ".", "pricedb_session", ":", "self", ".", "pricedb_session", ".", "close", "(", ")" ]
Close all database sessions
[ "Close", "all", "database", "sessions" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/stocks.py#L31-L36
MisterY/asset-allocation
asset_allocation/stocks.py
StocksInfo.load_stock_quantity
def load_stock_quantity(self, symbol: str) -> Decimal(0): """ retrieves stock quantity """ book = self.get_gc_book() collection = SecuritiesAggregate(book) sec = collection.get_aggregate_for_symbol(symbol) quantity = sec.get_quantity() return quantity
python
def load_stock_quantity(self, symbol: str) -> Decimal(0): """ retrieves stock quantity """ book = self.get_gc_book() collection = SecuritiesAggregate(book) sec = collection.get_aggregate_for_symbol(symbol) quantity = sec.get_quantity() return quantity
[ "def", "load_stock_quantity", "(", "self", ",", "symbol", ":", "str", ")", "->", "Decimal", "(", "0", ")", ":", "book", "=", "self", ".", "get_gc_book", "(", ")", "collection", "=", "SecuritiesAggregate", "(", "book", ")", "sec", "=", "collection", ".", ...
retrieves stock quantity
[ "retrieves", "stock", "quantity" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/stocks.py#L38-L45
MisterY/asset-allocation
asset_allocation/stocks.py
StocksInfo.get_gc_book
def get_gc_book(self): """ Returns the GnuCash db session """ if not self.gc_book: gc_db = self.config.get(ConfigKeys.gnucash_book_path) if not gc_db: raise AttributeError("GnuCash book path not configured.") # check if this is the abs file exists ...
python
def get_gc_book(self): """ Returns the GnuCash db session """ if not self.gc_book: gc_db = self.config.get(ConfigKeys.gnucash_book_path) if not gc_db: raise AttributeError("GnuCash book path not configured.") # check if this is the abs file exists ...
[ "def", "get_gc_book", "(", "self", ")", ":", "if", "not", "self", ".", "gc_book", ":", "gc_db", "=", "self", ".", "config", ".", "get", "(", "ConfigKeys", ".", "gnucash_book_path", ")", "if", "not", "gc_db", ":", "raise", "AttributeError", "(", "\"GnuCas...
Returns the GnuCash db session
[ "Returns", "the", "GnuCash", "db", "session" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/stocks.py#L55-L69
MisterY/asset-allocation
asset_allocation/stocks.py
StocksInfo.get_symbols_with_positive_balances
def get_symbols_with_positive_balances(self) -> List[str]: """ Identifies all the securities with positive balances """ from gnucash_portfolio import BookAggregate holdings = [] with BookAggregate() as book: # query = book.securities.query.filter(Commodity.) hol...
python
def get_symbols_with_positive_balances(self) -> List[str]: """ Identifies all the securities with positive balances """ from gnucash_portfolio import BookAggregate holdings = [] with BookAggregate() as book: # query = book.securities.query.filter(Commodity.) hol...
[ "def", "get_symbols_with_positive_balances", "(", "self", ")", "->", "List", "[", "str", "]", ":", "from", "gnucash_portfolio", "import", "BookAggregate", "holdings", "=", "[", "]", "with", "BookAggregate", "(", ")", "as", "book", ":", "# query = book.securities.q...
Identifies all the securities with positive balances
[ "Identifies", "all", "the", "securities", "with", "positive", "balances" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/stocks.py#L71-L90
MisterY/asset-allocation
asset_allocation/stocks.py
StocksInfo.__get_pricedb_session
def __get_pricedb_session(self): """ Provides initialization and access to module-level session """ from pricedb import dal if not self.pricedb_session: self.pricedb_session = dal.get_default_session() return self.pricedb_session
python
def __get_pricedb_session(self): """ Provides initialization and access to module-level session """ from pricedb import dal if not self.pricedb_session: self.pricedb_session = dal.get_default_session() return self.pricedb_session
[ "def", "__get_pricedb_session", "(", "self", ")", ":", "from", "pricedb", "import", "dal", "if", "not", "self", ".", "pricedb_session", ":", "self", ".", "pricedb_session", "=", "dal", ".", "get_default_session", "(", ")", "return", "self", ".", "pricedb_sessi...
Provides initialization and access to module-level session
[ "Provides", "initialization", "and", "access", "to", "module", "-", "level", "session" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/stocks.py#L125-L131
MisterY/asset-allocation
asset_allocation/stocklink_cli.py
add
def add(assetclass: int, symbol: str): """ Add a stock to an asset class """ assert isinstance(symbol, str) assert isinstance(assetclass, int) symbol = symbol.upper() app = AppAggregate() new_item = app.add_stock_to_class(assetclass, symbol) print(f"Record added: {new_item}.")
python
def add(assetclass: int, symbol: str): """ Add a stock to an asset class """ assert isinstance(symbol, str) assert isinstance(assetclass, int) symbol = symbol.upper() app = AppAggregate() new_item = app.add_stock_to_class(assetclass, symbol) print(f"Record added: {new_item}.")
[ "def", "add", "(", "assetclass", ":", "int", ",", "symbol", ":", "str", ")", ":", "assert", "isinstance", "(", "symbol", ",", "str", ")", "assert", "isinstance", "(", "assetclass", ",", "int", ")", "symbol", "=", "symbol", ".", "upper", "(", ")", "ap...
Add a stock to an asset class
[ "Add", "a", "stock", "to", "an", "asset", "class" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/stocklink_cli.py#L23-L31
MisterY/asset-allocation
asset_allocation/stocklink_cli.py
unallocated
def unallocated(): """ Identify unallocated holdings """ app = AppAggregate() app.logger = logger unalloc = app.find_unallocated_holdings() if not unalloc: print(f"No unallocated holdings.") for item in unalloc: print(item)
python
def unallocated(): """ Identify unallocated holdings """ app = AppAggregate() app.logger = logger unalloc = app.find_unallocated_holdings() if not unalloc: print(f"No unallocated holdings.") for item in unalloc: print(item)
[ "def", "unallocated", "(", ")", ":", "app", "=", "AppAggregate", "(", ")", "app", ".", "logger", "=", "logger", "unalloc", "=", "app", ".", "find_unallocated_holdings", "(", ")", "if", "not", "unalloc", ":", "print", "(", "f\"No unallocated holdings.\"", ")"...
Identify unallocated holdings
[ "Identify", "unallocated", "holdings" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/stocklink_cli.py#L74-L84
MisterY/asset-allocation
asset_allocation/formatters.py
AsciiFormatter.format
def format(self, model: AssetAllocationModel, full: bool = False): """ Returns the view-friendly output of the aa model """ self.full = full # Header output = f"Asset Allocation model, total: {model.currency} {model.total_amount:,.2f}\n" # Column Headers for column in s...
python
def format(self, model: AssetAllocationModel, full: bool = False): """ Returns the view-friendly output of the aa model """ self.full = full # Header output = f"Asset Allocation model, total: {model.currency} {model.total_amount:,.2f}\n" # Column Headers for column in s...
[ "def", "format", "(", "self", ",", "model", ":", "AssetAllocationModel", ",", "full", ":", "bool", "=", "False", ")", ":", "self", ".", "full", "=", "full", "# Header", "output", "=", "f\"Asset Allocation model, total: {model.currency} {model.total_amount:,.2f}\\n\"",...
Returns the view-friendly output of the aa model
[ "Returns", "the", "view", "-", "friendly", "output", "of", "the", "aa", "model" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/formatters.py#L26-L50
MisterY/asset-allocation
asset_allocation/formatters.py
AsciiFormatter.__format_row
def __format_row(self, row: AssetAllocationViewModel): """ display-format one row Formats one Asset Class record """ output = "" index = 0 # Name value = row.name # Indent according to depth. for _ in range(0, row.depth): value = f" {value}"...
python
def __format_row(self, row: AssetAllocationViewModel): """ display-format one row Formats one Asset Class record """ output = "" index = 0 # Name value = row.name # Indent according to depth. for _ in range(0, row.depth): value = f" {value}"...
[ "def", "__format_row", "(", "self", ",", "row", ":", "AssetAllocationViewModel", ")", ":", "output", "=", "\"\"", "index", "=", "0", "# Name", "value", "=", "row", ".", "name", "# Indent according to depth.", "for", "_", "in", "range", "(", "0", ",", "row"...
display-format one row Formats one Asset Class record
[ "display", "-", "format", "one", "row", "Formats", "one", "Asset", "Class", "record" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/formatters.py#L52-L122
MisterY/asset-allocation
asset_allocation/formatters.py
AsciiFormatter.append_num_column
def append_num_column(self, text: str, index: int): """ Add value to the output row, width based on index """ width = self.columns[index]["width"] return f"{text:>{width}}"
python
def append_num_column(self, text: str, index: int): """ Add value to the output row, width based on index """ width = self.columns[index]["width"] return f"{text:>{width}}"
[ "def", "append_num_column", "(", "self", ",", "text", ":", "str", ",", "index", ":", "int", ")", ":", "width", "=", "self", ".", "columns", "[", "index", "]", "[", "\"width\"", "]", "return", "f\"{text:>{width}}\"" ]
Add value to the output row, width based on index
[ "Add", "value", "to", "the", "output", "row", "width", "based", "on", "index" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/formatters.py#L124-L127
MisterY/asset-allocation
asset_allocation/formatters.py
AsciiFormatter.append_text_column
def append_text_column(self, text: str, index: int): """ Add value to the output row, width based on index """ width = self.columns[index]["width"] return f"{text:<{width}}"
python
def append_text_column(self, text: str, index: int): """ Add value to the output row, width based on index """ width = self.columns[index]["width"] return f"{text:<{width}}"
[ "def", "append_text_column", "(", "self", ",", "text", ":", "str", ",", "index", ":", "int", ")", ":", "width", "=", "self", ".", "columns", "[", "index", "]", "[", "\"width\"", "]", "return", "f\"{text:<{width}}\"" ]
Add value to the output row, width based on index
[ "Add", "value", "to", "the", "output", "row", "width", "based", "on", "index" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/formatters.py#L129-L132
MisterY/asset-allocation
asset_allocation/maps.py
AssetClassMapper.map_entity
def map_entity(self, entity: dal.AssetClass): """ maps data from entity -> object """ obj = model.AssetClass() obj.id = entity.id obj.parent_id = entity.parentid obj.name = entity.name obj.allocation = entity.allocation obj.sort_order = entity.sortorder #...
python
def map_entity(self, entity: dal.AssetClass): """ maps data from entity -> object """ obj = model.AssetClass() obj.id = entity.id obj.parent_id = entity.parentid obj.name = entity.name obj.allocation = entity.allocation obj.sort_order = entity.sortorder #...
[ "def", "map_entity", "(", "self", ",", "entity", ":", "dal", ".", "AssetClass", ")", ":", "obj", "=", "model", ".", "AssetClass", "(", ")", "obj", ".", "id", "=", "entity", ".", "id", "obj", ".", "parent_id", "=", "entity", ".", "parentid", "obj", ...
maps data from entity -> object
[ "maps", "data", "from", "entity", "-", ">", "object" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/maps.py#L14-L28
MisterY/asset-allocation
asset_allocation/maps.py
ModelMapper.map_to_linear
def map_to_linear(self, with_stocks: bool=False): """ Maps the tree to a linear representation suitable for display """ result = [] for ac in self.model.classes: rows = self.__get_ac_tree(ac, with_stocks) result += rows return result
python
def map_to_linear(self, with_stocks: bool=False): """ Maps the tree to a linear representation suitable for display """ result = [] for ac in self.model.classes: rows = self.__get_ac_tree(ac, with_stocks) result += rows return result
[ "def", "map_to_linear", "(", "self", ",", "with_stocks", ":", "bool", "=", "False", ")", ":", "result", "=", "[", "]", "for", "ac", "in", "self", ".", "model", ".", "classes", ":", "rows", "=", "self", ".", "__get_ac_tree", "(", "ac", ",", "with_stoc...
Maps the tree to a linear representation suitable for display
[ "Maps", "the", "tree", "to", "a", "linear", "representation", "suitable", "for", "display" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/maps.py#L36-L43
MisterY/asset-allocation
asset_allocation/maps.py
ModelMapper.__get_ac_tree
def __get_ac_tree(self, ac: model.AssetClass, with_stocks: bool): """ formats the ac tree - entity with child elements """ output = [] output.append(self.__get_ac_row(ac)) for child in ac.classes: output += self.__get_ac_tree(child, with_stocks) if with_stocks: ...
python
def __get_ac_tree(self, ac: model.AssetClass, with_stocks: bool): """ formats the ac tree - entity with child elements """ output = [] output.append(self.__get_ac_row(ac)) for child in ac.classes: output += self.__get_ac_tree(child, with_stocks) if with_stocks: ...
[ "def", "__get_ac_tree", "(", "self", ",", "ac", ":", "model", ".", "AssetClass", ",", "with_stocks", ":", "bool", ")", ":", "output", "=", "[", "]", "output", ".", "append", "(", "self", ".", "__get_ac_row", "(", "ac", ")", ")", "for", "child", "in",...
formats the ac tree - entity with child elements
[ "formats", "the", "ac", "tree", "-", "entity", "with", "child", "elements" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/maps.py#L45-L62
MisterY/asset-allocation
asset_allocation/maps.py
ModelMapper.__get_ac_row
def __get_ac_row(self, ac: model.AssetClass) -> AssetAllocationViewModel: """ Formats one Asset Class record """ view_model = AssetAllocationViewModel() view_model.depth = ac.depth # Name view_model.name = ac.name view_model.set_allocation = ac.allocation ...
python
def __get_ac_row(self, ac: model.AssetClass) -> AssetAllocationViewModel: """ Formats one Asset Class record """ view_model = AssetAllocationViewModel() view_model.depth = ac.depth # Name view_model.name = ac.name view_model.set_allocation = ac.allocation ...
[ "def", "__get_ac_row", "(", "self", ",", "ac", ":", "model", ".", "AssetClass", ")", "->", "AssetAllocationViewModel", ":", "view_model", "=", "AssetAllocationViewModel", "(", ")", "view_model", ".", "depth", "=", "ac", ".", "depth", "# Name", "view_model", "....
Formats one Asset Class record
[ "Formats", "one", "Asset", "Class", "record" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/maps.py#L64-L85
MisterY/asset-allocation
asset_allocation/maps.py
ModelMapper.__get_stock_row
def __get_stock_row(self, stock: Stock, depth: int) -> str: """ formats stock row """ assert isinstance(stock, Stock) view_model = AssetAllocationViewModel() view_model.depth = depth # Symbol view_model.name = stock.symbol # Current allocation view_mod...
python
def __get_stock_row(self, stock: Stock, depth: int) -> str: """ formats stock row """ assert isinstance(stock, Stock) view_model = AssetAllocationViewModel() view_model.depth = depth # Symbol view_model.name = stock.symbol # Current allocation view_mod...
[ "def", "__get_stock_row", "(", "self", ",", "stock", ":", "Stock", ",", "depth", ":", "int", ")", "->", "str", ":", "assert", "isinstance", "(", "stock", ",", "Stock", ")", "view_model", "=", "AssetAllocationViewModel", "(", ")", "view_model", ".", "depth"...
formats stock row
[ "formats", "stock", "row" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/maps.py#L87-L108
MisterY/asset-allocation
asset_allocation/maps.py
ModelMapper.__get_cash_row
def __get_cash_row(self, item: CashBalance, depth: int) -> str: """ formats stock row """ assert isinstance(item, CashBalance) view_model = AssetAllocationViewModel() view_model.depth = depth # Symbol view_model.name = item.symbol # Value in base currency ...
python
def __get_cash_row(self, item: CashBalance, depth: int) -> str: """ formats stock row """ assert isinstance(item, CashBalance) view_model = AssetAllocationViewModel() view_model.depth = depth # Symbol view_model.name = item.symbol # Value in base currency ...
[ "def", "__get_cash_row", "(", "self", ",", "item", ":", "CashBalance", ",", "depth", ":", "int", ")", "->", "str", ":", "assert", "isinstance", "(", "item", ",", "CashBalance", ")", "view_model", "=", "AssetAllocationViewModel", "(", ")", "view_model", ".", ...
formats stock row
[ "formats", "stock", "row" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/maps.py#L110-L128
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.create_asset_class
def create_asset_class(self, item: AssetClass): """ Inserts the record """ session = self.open_session() session.add(item) session.commit()
python
def create_asset_class(self, item: AssetClass): """ Inserts the record """ session = self.open_session() session.add(item) session.commit()
[ "def", "create_asset_class", "(", "self", ",", "item", ":", "AssetClass", ")", ":", "session", "=", "self", ".", "open_session", "(", ")", "session", ".", "add", "(", "item", ")", "session", ".", "commit", "(", ")" ]
Inserts the record
[ "Inserts", "the", "record" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L20-L24
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.add_stock_to_class
def add_stock_to_class(self, assetclass_id: int, symbol: str): """ Add a stock link to an asset class """ assert isinstance(symbol, str) assert isinstance(assetclass_id, int) item = AssetClassStock() item.assetclassid = assetclass_id item.symbol = symbol session...
python
def add_stock_to_class(self, assetclass_id: int, symbol: str): """ Add a stock link to an asset class """ assert isinstance(symbol, str) assert isinstance(assetclass_id, int) item = AssetClassStock() item.assetclassid = assetclass_id item.symbol = symbol session...
[ "def", "add_stock_to_class", "(", "self", ",", "assetclass_id", ":", "int", ",", "symbol", ":", "str", ")", ":", "assert", "isinstance", "(", "symbol", ",", "str", ")", "assert", "isinstance", "(", "assetclass_id", ",", "int", ")", "item", "=", "AssetClass...
Add a stock link to an asset class
[ "Add", "a", "stock", "link", "to", "an", "asset", "class" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L26-L39
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.delete
def delete(self, id: int): """ Delete asset class """ assert isinstance(id, int) self.open_session() to_delete = self.get(id) self.session.delete(to_delete) self.save()
python
def delete(self, id: int): """ Delete asset class """ assert isinstance(id, int) self.open_session() to_delete = self.get(id) self.session.delete(to_delete) self.save()
[ "def", "delete", "(", "self", ",", "id", ":", "int", ")", ":", "assert", "isinstance", "(", "id", ",", "int", ")", "self", ".", "open_session", "(", ")", "to_delete", "=", "self", ".", "get", "(", "id", ")", "self", ".", "session", ".", "delete", ...
Delete asset class
[ "Delete", "asset", "class" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L41-L48
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.find_unallocated_holdings
def find_unallocated_holdings(self): """ Identifies any holdings that are not included in asset allocation """ # Get linked securities session = self.open_session() linked_entities = session.query(AssetClassStock).all() linked = [] # linked = map(lambda x: f"{x.symbol}", ...
python
def find_unallocated_holdings(self): """ Identifies any holdings that are not included in asset allocation """ # Get linked securities session = self.open_session() linked_entities = session.query(AssetClassStock).all() linked = [] # linked = map(lambda x: f"{x.symbol}", ...
[ "def", "find_unallocated_holdings", "(", "self", ")", ":", "# Get linked securities", "session", "=", "self", ".", "open_session", "(", ")", "linked_entities", "=", "session", ".", "query", "(", "AssetClassStock", ")", ".", "all", "(", ")", "linked", "=", "[",...
Identifies any holdings that are not included in asset allocation
[ "Identifies", "any", "holdings", "that", "are", "not", "included", "in", "asset", "allocation" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L50-L77
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.get
def get(self, id: int) -> AssetClass: """ Loads Asset Class """ self.open_session() item = self.session.query(AssetClass).filter( AssetClass.id == id).first() return item
python
def get(self, id: int) -> AssetClass: """ Loads Asset Class """ self.open_session() item = self.session.query(AssetClass).filter( AssetClass.id == id).first() return item
[ "def", "get", "(", "self", ",", "id", ":", "int", ")", "->", "AssetClass", ":", "self", ".", "open_session", "(", ")", "item", "=", "self", ".", "session", ".", "query", "(", "AssetClass", ")", ".", "filter", "(", "AssetClass", ".", "id", "==", "id...
Loads Asset Class
[ "Loads", "Asset", "Class" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L79-L84
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.open_session
def open_session(self): """ Opens a db session and returns it """ from .dal import get_session cfg = Config() cfg.logger = self.logger db_path = cfg.get(ConfigKeys.asset_allocation_database_path) self.session = get_session(db_path) return self.session
python
def open_session(self): """ Opens a db session and returns it """ from .dal import get_session cfg = Config() cfg.logger = self.logger db_path = cfg.get(ConfigKeys.asset_allocation_database_path) self.session = get_session(db_path) return self.session
[ "def", "open_session", "(", "self", ")", ":", "from", ".", "dal", "import", "get_session", "cfg", "=", "Config", "(", ")", "cfg", ".", "logger", "=", "self", ".", "logger", "db_path", "=", "cfg", ".", "get", "(", "ConfigKeys", ".", "asset_allocation_data...
Opens a db session and returns it
[ "Opens", "a", "db", "session", "and", "returns", "it" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L86-L95
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.get_asset_allocation
def get_asset_allocation(self): """ Creates and populates the Asset Allocation model. The main function of the app. """ # load from db # TODO set the base currency base_currency = "EUR" loader = AssetAllocationLoader(base_currency=base_currency) loader.logger = self.logg...
python
def get_asset_allocation(self): """ Creates and populates the Asset Allocation model. The main function of the app. """ # load from db # TODO set the base currency base_currency = "EUR" loader = AssetAllocationLoader(base_currency=base_currency) loader.logger = self.logg...
[ "def", "get_asset_allocation", "(", "self", ")", ":", "# load from db", "# TODO set the base currency", "base_currency", "=", "\"EUR\"", "loader", "=", "AssetAllocationLoader", "(", "base_currency", "=", "base_currency", ")", "loader", ".", "logger", "=", "self", ".",...
Creates and populates the Asset Allocation model. The main function of the app.
[ "Creates", "and", "populates", "the", "Asset", "Allocation", "model", ".", "The", "main", "function", "of", "the", "app", "." ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L101-L131
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.get_asset_classes_for_security
def get_asset_classes_for_security(self, namespace: str, symbol: str) -> List[AssetClass]: """ Find all asset classes (should be only one at the moment, though!) to which the symbol belongs """ full_symbol = symbol if namespace: full_symbol = f"{namespace}:{symbol}" result =...
python
def get_asset_classes_for_security(self, namespace: str, symbol: str) -> List[AssetClass]: """ Find all asset classes (should be only one at the moment, though!) to which the symbol belongs """ full_symbol = symbol if namespace: full_symbol = f"{namespace}:{symbol}" result =...
[ "def", "get_asset_classes_for_security", "(", "self", ",", "namespace", ":", "str", ",", "symbol", ":", "str", ")", "->", "List", "[", "AssetClass", "]", ":", "full_symbol", "=", "symbol", "if", "namespace", ":", "full_symbol", "=", "f\"{namespace}:{symbol}\"", ...
Find all asset classes (should be only one at the moment, though!) to which the symbol belongs
[ "Find", "all", "asset", "classes", "(", "should", "be", "only", "one", "at", "the", "moment", "though!", ")", "to", "which", "the", "symbol", "belongs" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L133-L144
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.validate_model
def validate_model(self): """ Validate the model """ model: AssetAllocationModel = self.get_asset_allocation_model() model.logger = self.logger valid = model.validate() if valid: print(f"The model is valid. Congratulations") else: print(f"The mode...
python
def validate_model(self): """ Validate the model """ model: AssetAllocationModel = self.get_asset_allocation_model() model.logger = self.logger valid = model.validate() if valid: print(f"The model is valid. Congratulations") else: print(f"The mode...
[ "def", "validate_model", "(", "self", ")", ":", "model", ":", "AssetAllocationModel", "=", "self", ".", "get_asset_allocation_model", "(", ")", "model", ".", "logger", "=", "self", ".", "logger", "valid", "=", "model", ".", "validate", "(", ")", "if", "val...
Validate the model
[ "Validate", "the", "model" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L146-L155
MisterY/asset-allocation
asset_allocation/app.py
AppAggregate.export_symbols
def export_symbols(self): """ Exports all used symbols """ session = self.open_session() links = session.query(AssetClassStock).order_by( AssetClassStock.symbol).all() output = [] for link in links: output.append(link.symbol + '\n') # Save output ...
python
def export_symbols(self): """ Exports all used symbols """ session = self.open_session() links = session.query(AssetClassStock).order_by( AssetClassStock.symbol).all() output = [] for link in links: output.append(link.symbol + '\n') # Save output ...
[ "def", "export_symbols", "(", "self", ")", ":", "session", "=", "self", ".", "open_session", "(", ")", "links", "=", "session", ".", "query", "(", "AssetClassStock", ")", ".", "order_by", "(", "AssetClassStock", ".", "symbol", ")", ".", "all", "(", ")", ...
Exports all used symbols
[ "Exports", "all", "used", "symbols" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/app.py#L157-L170
MisterY/asset-allocation
asset_allocation/config.py
Config.__read_config
def __read_config(self, file_path: str): """ Read the config file """ if not os.path.exists(file_path): raise FileNotFoundError("File path not found: %s", file_path) # check if file exists if not os.path.isfile(file_path): log(ERROR, "file not found: %s", file_pat...
python
def __read_config(self, file_path: str): """ Read the config file """ if not os.path.exists(file_path): raise FileNotFoundError("File path not found: %s", file_path) # check if file exists if not os.path.isfile(file_path): log(ERROR, "file not found: %s", file_pat...
[ "def", "__read_config", "(", "self", ",", "file_path", ":", "str", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "file_path", ")", ":", "raise", "FileNotFoundError", "(", "\"File path not found: %s\"", ",", "file_path", ")", "# check if file ex...
Read the config file
[ "Read", "the", "config", "file" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/config.py#L54-L63
MisterY/asset-allocation
asset_allocation/config.py
Config.__create_user_config
def __create_user_config(self): """ Copy the config template into user's directory """ src_path = self.__get_config_template_path() src = os.path.abspath(src_path) if not os.path.exists(src): log(ERROR, "Config template not found %s", src) raise FileNotFoundError(...
python
def __create_user_config(self): """ Copy the config template into user's directory """ src_path = self.__get_config_template_path() src = os.path.abspath(src_path) if not os.path.exists(src): log(ERROR, "Config template not found %s", src) raise FileNotFoundError(...
[ "def", "__create_user_config", "(", "self", ")", ":", "src_path", "=", "self", ".", "__get_config_template_path", "(", ")", "src", "=", "os", ".", "path", ".", "abspath", "(", "src_path", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "src", ...
Copy the config template into user's directory
[ "Copy", "the", "config", "template", "into", "user", "s", "directory" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/config.py#L75-L88
MisterY/asset-allocation
asset_allocation/config_cli.py
set
def set(aadb, cur): """ Sets the values in the config file """ cfg = Config() edited = False if aadb: cfg.set(ConfigKeys.asset_allocation_database_path, aadb) print(f"The database has been set to {aadb}.") edited = True if cur: cfg.set(ConfigKeys.default_currenc...
python
def set(aadb, cur): """ Sets the values in the config file """ cfg = Config() edited = False if aadb: cfg.set(ConfigKeys.asset_allocation_database_path, aadb) print(f"The database has been set to {aadb}.") edited = True if cur: cfg.set(ConfigKeys.default_currenc...
[ "def", "set", "(", "aadb", ",", "cur", ")", ":", "cfg", "=", "Config", "(", ")", "edited", "=", "False", "if", "aadb", ":", "cfg", ".", "set", "(", "ConfigKeys", ".", "asset_allocation_database_path", ",", "aadb", ")", "print", "(", "f\"The database has ...
Sets the values in the config file
[ "Sets", "the", "values", "in", "the", "config", "file" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/config_cli.py#L31-L49
MisterY/asset-allocation
asset_allocation/config_cli.py
get
def get(aadb: str): """ Retrieves a value from config """ if (aadb): cfg = Config() value = cfg.get(ConfigKeys.asset_allocation_database_path) click.echo(value) if not aadb: click.echo("Use --help for more information.")
python
def get(aadb: str): """ Retrieves a value from config """ if (aadb): cfg = Config() value = cfg.get(ConfigKeys.asset_allocation_database_path) click.echo(value) if not aadb: click.echo("Use --help for more information.")
[ "def", "get", "(", "aadb", ":", "str", ")", ":", "if", "(", "aadb", ")", ":", "cfg", "=", "Config", "(", ")", "value", "=", "cfg", ".", "get", "(", "ConfigKeys", ".", "asset_allocation_database_path", ")", "click", ".", "echo", "(", "value", ")", "...
Retrieves a value from config
[ "Retrieves", "a", "value", "from", "config" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/config_cli.py#L53-L61
MisterY/asset-allocation
asset_allocation/model.py
_AssetBase.fullname
def fullname(self): """ includes the full path with parent names """ prefix = "" if self.parent: if self.parent.fullname: prefix = self.parent.fullname + ":" else: # Only the root does not have a parent. In that case we also don't need a name. ...
python
def fullname(self): """ includes the full path with parent names """ prefix = "" if self.parent: if self.parent.fullname: prefix = self.parent.fullname + ":" else: # Only the root does not have a parent. In that case we also don't need a name. ...
[ "def", "fullname", "(", "self", ")", ":", "prefix", "=", "\"\"", "if", "self", ".", "parent", ":", "if", "self", ".", "parent", ".", "fullname", ":", "prefix", "=", "self", ".", "parent", ".", "fullname", "+", "\":\"", "else", ":", "# Only the root doe...
includes the full path with parent names
[ "includes", "the", "full", "path", "with", "parent", "names" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/model.py#L67-L77
MisterY/asset-allocation
asset_allocation/model.py
Stock.value
def value(self) -> Decimal: """ Value of the holdings in exchange currency. Value = Quantity * Price """ assert isinstance(self.price, Decimal) return self.quantity * self.price
python
def value(self) -> Decimal: """ Value of the holdings in exchange currency. Value = Quantity * Price """ assert isinstance(self.price, Decimal) return self.quantity * self.price
[ "def", "value", "(", "self", ")", "->", "Decimal", ":", "assert", "isinstance", "(", "self", ".", "price", ",", "Decimal", ")", "return", "self", ".", "quantity", "*", "self", ".", "price" ]
Value of the holdings in exchange currency. Value = Quantity * Price
[ "Value", "of", "the", "holdings", "in", "exchange", "currency", ".", "Value", "=", "Quantity", "*", "Price" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/model.py#L116-L123
MisterY/asset-allocation
asset_allocation/model.py
Stock.asset_class
def asset_class(self) -> str: """ Returns the full asset class path for this stock """ result = self.parent.name if self.parent else "" # Iterate to the top asset class and add names. cursor = self.parent while cursor: result = cursor.name + ":" + result c...
python
def asset_class(self) -> str: """ Returns the full asset class path for this stock """ result = self.parent.name if self.parent else "" # Iterate to the top asset class and add names. cursor = self.parent while cursor: result = cursor.name + ":" + result c...
[ "def", "asset_class", "(", "self", ")", "->", "str", ":", "result", "=", "self", ".", "parent", ".", "name", "if", "self", ".", "parent", "else", "\"\"", "# Iterate to the top asset class and add names.", "cursor", "=", "self", ".", "parent", "while", "cursor"...
Returns the full asset class path for this stock
[ "Returns", "the", "full", "asset", "class", "path", "for", "this", "stock" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/model.py#L126-L134
MisterY/asset-allocation
asset_allocation/model.py
AssetClass.child_allocation
def child_allocation(self): """ The sum of all child asset classes' allocations """ sum = Decimal(0) if self.classes: for child in self.classes: sum += child.child_allocation else: # This is not a branch but a leaf. Return own allocation. ...
python
def child_allocation(self): """ The sum of all child asset classes' allocations """ sum = Decimal(0) if self.classes: for child in self.classes: sum += child.child_allocation else: # This is not a branch but a leaf. Return own allocation. ...
[ "def", "child_allocation", "(", "self", ")", ":", "sum", "=", "Decimal", "(", "0", ")", "if", "self", ".", "classes", ":", "for", "child", "in", "self", ".", "classes", ":", "sum", "+=", "child", ".", "child_allocation", "else", ":", "# This is not a bra...
The sum of all child asset classes' allocations
[ "The", "sum", "of", "all", "child", "asset", "classes", "allocations" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/model.py#L152-L162
MisterY/asset-allocation
asset_allocation/model.py
AssetAllocationModel.get_class_by_id
def get_class_by_id(self, ac_id: int) -> AssetClass: """ Finds the asset class by id """ assert isinstance(ac_id, int) # iterate recursively for ac in self.asset_classes: if ac.id == ac_id: return ac # if nothing returned so far. return None
python
def get_class_by_id(self, ac_id: int) -> AssetClass: """ Finds the asset class by id """ assert isinstance(ac_id, int) # iterate recursively for ac in self.asset_classes: if ac.id == ac_id: return ac # if nothing returned so far. return None
[ "def", "get_class_by_id", "(", "self", ",", "ac_id", ":", "int", ")", "->", "AssetClass", ":", "assert", "isinstance", "(", "ac_id", ",", "int", ")", "# iterate recursively", "for", "ac", "in", "self", ".", "asset_classes", ":", "if", "ac", ".", "id", "=...
Finds the asset class by id
[ "Finds", "the", "asset", "class", "by", "id" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/model.py#L182-L191
MisterY/asset-allocation
asset_allocation/model.py
AssetAllocationModel.get_cash_asset_class
def get_cash_asset_class(self) -> AssetClass: """ Find the cash asset class by name. """ for ac in self.asset_classes: if ac.name.lower() == "cash": return ac return None
python
def get_cash_asset_class(self) -> AssetClass: """ Find the cash asset class by name. """ for ac in self.asset_classes: if ac.name.lower() == "cash": return ac return None
[ "def", "get_cash_asset_class", "(", "self", ")", "->", "AssetClass", ":", "for", "ac", "in", "self", ".", "asset_classes", ":", "if", "ac", ".", "name", ".", "lower", "(", ")", "==", "\"cash\"", ":", "return", "ac", "return", "None" ]
Find the cash asset class by name.
[ "Find", "the", "cash", "asset", "class", "by", "name", "." ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/model.py#L193-L198
MisterY/asset-allocation
asset_allocation/model.py
AssetAllocationModel.validate
def validate(self) -> bool: """ Validate that the values match. Incomplete! """ # Asset class allocation should match the sum of children's allocations. # Each group should be compared. sum = Decimal(0) # Go through each asset class, not just the top level. for ac in sel...
python
def validate(self) -> bool: """ Validate that the values match. Incomplete! """ # Asset class allocation should match the sum of children's allocations. # Each group should be compared. sum = Decimal(0) # Go through each asset class, not just the top level. for ac in sel...
[ "def", "validate", "(", "self", ")", "->", "bool", ":", "# Asset class allocation should match the sum of children's allocations.", "# Each group should be compared.", "sum", "=", "Decimal", "(", "0", ")", "# Go through each asset class, not just the top level.", "for", "ac", "...
Validate that the values match. Incomplete!
[ "Validate", "that", "the", "values", "match", ".", "Incomplete!" ]
train
https://github.com/MisterY/asset-allocation/blob/72239aa20762cda67c091f27b86e65d61bf3b613/asset_allocation/model.py#L200-L227