Example #1
0
def report_no_input_file():
    '''Print the information on data file that was not found and on all locations it has been looked for at.'''
    file_locations = shared.get_input_file_locations(_input_file_name)
    shared.print_separator()
    print(
        'The input file was not found. Please place it at one of the following locations:'
    )
    for location in file_locations:
        print(location)
    shared.print_separator()
Example #2
0
def output_summary(election_summary: ElectionSummary, file=sys.stdout):
    '''
    Print the contents of the election summary to the specific file.

    :param ElectionSummary election_summary: Election summary
    :param file file: File to output analysis to. Defaults to sys.stdout 
    '''
    shared.print_separator(file)
    print('Election Results Analysis', file=file)
    shared.print_separator(file)
    print(f'Total Votes: {election_summary.total_vote_count}', file=file)
    shared.print_separator(file)
    for candidate in election_summary.candidates:
        print(
            f'{candidate.name}: {candidate.vote_percentage:.2%} ({candidate.vote_count})',
            file=file)
    shared.print_separator(file)
    print(f'Winner: {election_summary.winner_name}', file=file)
    shared.print_separator(file)
Example #3
0
def output_analysis(analysis: FinancialAnalysis, file=sys.stdout):
    '''
    Print the contents of financial analysis.

    :param FinancialAnalysis analysis: financial analysis
    :param file file: file to output analysis to. Defaults to sys.stdout 
    '''
    shared.print_separator(file)
    print('Financial Analysis', file=file)
    shared.print_separator(file)
    print(f'Total Months: {analysis.month_count}', file=file)
    print(f'Total PnL: ${analysis.total_pnl}', file=file)
    print(f'Average Change: ${analysis.average_pnl_change:.2f}', file=file)
    print(
        f'Greatest Increase in Profits: {"N/A" if analysis.max_increase is None else f"{analysis.max_increase.month} (${analysis.max_increase.pnl})"}',
        file=file)
    print(
        f'Greatest Decrease in Profits: {"N/A" if analysis.min_decrease is None else f"{analysis.min_decrease.month} (${analysis.min_decrease.pnl})"}',
        file=file)
Example #4
0
def main():
    input_file_path = shared.get_input_file_path(_input_file_name)
    if input_file_path == '':
        report_no_input_file()
        exit(1)
    data = get_data(input_file_path)
    # If we don't have any votes at all we won't be able to generate the summary
    if len(data) == 0:
        report_no_data()
        exit(2)
    election_summary = generate_summary(data)
    # Output summary to the console
    output_summary(election_summary)
    # Output analysis to the file
    output_file_path = os.path.join('..', 'Output')
    if not os.path.exists(output_file_path):
        os.mkdir(output_file_path)
    output_file_path = os.path.join(output_file_path, _output_file_name)
    with open(output_file_path, 'w+', encoding='UTF-8',
              newline='') as output_file:
        output_summary(election_summary, output_file)
    print('Saved election summary to ' + output_file_path)
    shared.print_separator()
Example #5
0
def main():
    input_file_path = shared.get_input_file_path(_input_file_name)
    if input_file_path == '':
        report_no_input_file()
        exit(1)
    data = get_data(input_file_path)
    # If we have less than two data points we won't be able to calculate the PnL changes between months
    if len(data) < 2:
        report_no_data()
        exit(2)
    analysis = analyze(data)
    # Output analysis to console
    output_analysis(analysis)
    # Output analysis to file
    output_file_path = os.path.join('..', 'Output')
    if not os.path.exists(output_file_path):
        os.mkdir(output_file_path)
    output_file_path = os.path.join(output_file_path, _output_file_name)
    with open(output_file_path, 'w+', encoding='UTF-8',
              newline='') as output_file:
        output_analysis(analysis, output_file)
    shared.print_separator()
    print('Saved financial analysis to ' + output_file_path)
    shared.print_separator()
Example #6
0
def report_no_data():
    '''Print the information on being unable to calculate the election summary due to the lack of the data points.'''
    shared.print_separator()
    print('There is not enough data to calculate the election summary')
    shared.print_separator()
Example #7
0
def report_no_data():
    '''Print the information on being unable to perform the analysis due to the lack of the data points.'''
    shared.print_separator()
    print('There is not enough data to perform financial analysis')
    shared.print_separator()