# Create a Program to Read Battery Charging Time in Python Assignment Solution.

July 08, 2024
Dr. Matthew
🇨🇭 Switzerland
Python
Dr. Matthew Hernandez, an esteemed Computer Science researcher, obtained his PhD from ETH Zurich, Switzerland. With 6 years of experience under his belt, he has successfully completed over 400 Python assignments, demonstrating his proficiency and commitment to excellence.
Key Topics
• Instructions
• Objective
• Requirements and Specifications
Tip of the day
News

## Instructions

### Objective

Write your Python homework on how to read battery charging time using the Python language. Create a program that prompts the user to enter the current battery level and the charging rate. Based on this input, calculate and display the estimated time required to fully charge the battery. This exercise will help you practice taking user input, performing calculations, and displaying the output in Python.

## Requirements and Specifications

Source Code

```# -*- coding: utf-8 -*- """AliAssignment.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1yjeu4fehoNOo9yxnmp5S0CQ31ScBoRlG """ import pandas as pd import numpy as np import matplotlib.pyplot as plt from datetime import datetime """## Read files""" # Store data in dictionaries battery = dict() for i in range(1, 6): if not i in battery: battery[i] = { 'PW_EnergyRemaining': {'timestamps': [], 'values': []}, 'PW_FullPackEnergyAvailable': {'timestamps': [], 'values': []}, 'PW_AvailableChargePower': {'timestamps': [], 'values': []}, 'SOE': {'timestamps': [], 'values': []} } ile_name = '00' + str(i) + '.csv' df = pd.read_csv(file_name) # Drop NaN rows df = df.dropna() # Iterate through rows for index, row in df.iterrows(): timestamp = row['timestamp'] signal_name = row['signal_name'] value = row['signal_value'] battery[i][signal_name]['timestamps'].append(datetime.fromtimestamp(timestamp/1000)) battery[i][signal_name]['values'].append(value) # Calculate SOE for j in range(min(len(battery[i]['PW_EnergyRemaining']['values']), len(battery[i]['PW_FullPackEnergyAvailable']['values']))): x = battery[i]['PW_EnergyRemaining']['values'][j] y = battery[i]['PW_FullPackEnergyAvailable']['values'][j] battery[i]['SOE']['timestamps'].append(battery[i]['PW_EnergyRemaining']['timestamps'][j]) battery[i]['SOE']['values'].append(x/y) """ print(f"Battery {i}") for signal_name in battery[i]: print(f"There are {len(battery[i][signal_name]['values'])} values for {signal_name}") print("\n") """ """## Task 1 For battery 1, compute Monthly Average of percentage time for which Battery 001 has its PW_AvailableChargePower greater than or equal to its rate capacity """ print("\n*** TASK 1 ***") months = {} month_counter = {} for i in range(len(battery[1]['PW_AvailableChargePower']['values'])): val = battery[1]['PW_AvailableChargePower']['values'][i] month = battery[1]['PW_AvailableChargePower']['timestamps'][i].month if val >= 3300: months[month] = months.get(month, 0) + 1 month_counter[month] = month_counter.get(month, 0) + 1 # Now, calculate average for month in months: months[month] = months[month] / month_counter[month] # Print print("For month {} the average percent of time for which PW_AvailableChargePower >= Rate Capacity is {:.2f}%".format(month, months[month]*100.0)) x = list(months.keys()) y = list(months.values()) y = [i*100.0 for i in y] plt.figure(1) plt.bar(x, y) plt.xlabel('Month') plt.ylabel('Percentage of time (%)') plt.title('Monthly Average of Percentage Time of availability for Battery 1') plt.show() """## Task 2 Calculate monthly charge power availability """ print("\n*** TASK 2 ***") months = {} month_counter = {} for i in range(len(battery[1]['PW_AvailableChargePower']['values'])): val = battery[1]['PW_AvailableChargePower']['values'][i] month = battery[1]['PW_AvailableChargePower']['timestamps'][i].month SOE = battery[1]['SOE']['values'][i] if SOE < 0.9: months[month] = months.get(month, 0) + val month_counter[month] = month_counter.get(month, 0) + 1 # Now, calculate average for month in months: months[month] = months[month] / month_counter[month] # Print print("The monthly charge power availability for month {} is {:.2f} W".format(month, months[month])) # Show bar plot x = list(months.keys()) y = list(months.values()) plt.figure(1) plt.bar(x, y) plt.xlabel('Month') plt.ylabel('Power (W)') plt.title('Average Charge Power Availability') plt.show() """## Task 3""" print("\n*** TASK 3 ***") n = 3 months = {} months_counter = {} for i in range(1, 6): print(f"Battery {i}") for j in range(len(battery[i]['SOE']['values'])): val = battery[i]['PW_AvailableChargePower']['values'][j] month = battery[i]['PW_AvailableChargePower']['timestamps'][j].month SOE = battery[i]['SOE']['values'][j] if SOE < 0.9: months[month] = months.get(month, 0) + val month_counter[month] = month_counter.get(month, 0) + 1 # Now, calculate average for month in months: months[month] = months[month] / month_counter[month] # Print print("The monthly charge power availability for month {} is {:.2f} W".format(month, months[month])) # Show bar plot x = list(months.keys()) y = list(months.values()) plt.figure(n) plt.bar(x, y) plt.xlabel('Month') plt.ylabel('Power (W)') plt.title(f'Average Charge Power Availability between all batteries') plt.show() print("\n") n = n + 1 ```

## Similar Samples

Explore our curated samples at ProgrammingHomeworkHelp.com, showcasing our proficiency in Java, Python, C++, and more. Each assignment exemplifies our dedication to clarity, efficiency, and precision in programming solutions. Discover how our samples can guide you towards mastering programming concepts and achieving top grades.