Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

1 complete the code bellow to produce a cryptocurrency profit calculator using pyQt5 # standard imports import sys from PyQt5.QtCore import QDate from PyQt5.QtWidgets import

 1

complete the code bellow to produce a cryptocurrency profit calculator using pyQt5

# standard imports
import sys
from PyQt5.QtCore import QDate
from PyQt5.QtWidgets import QLabel, QComboBox, QCalendarWidget, QDialog, QApplication, QGridLayout, QSpinBox
from PyQt5 import QtCore
from decimal import Decimal


class CryptoTradeProfitCalculator(QDialog):
'''
Provides the following functionality:

- Allows the selection of the Crypto Coin to be purchased
- Allows the selection of the quantity to be purchased
- Allows the selection of the purchase date
- Displays the purchase total
- Allows the selection of the sell date
- Displays the sell total
- Displays the profit total
- Additional functionality

'''

def __init__(self):
'''
This method requires substantial updates
Each of the widgets should be suitably initalized and laid out
'''
super().__init__()

# setting up dictionary of Crypto Coins
self.data = self.make_data()
# sorting the dictionary of Crypto Coins by the keys. The keys at the high level are dates, so we are sorting by date
self.stocks = sorted(self.data.keys())

# the following 2 lines of code are for debugging purposee and show you how to access the self.data to get dates and prices
# print all the dates and close prices for BTC
print("all the dates and close prices for BTC", self.data['BTC'])
# print the close price for BTC on 04/29/2013
print("the close price for BTC on 04/29/2013",self.data['BTC'][QDate(2013,4,29)])

# The data in the file is in the following range
# first date in dataset - 29th Apr 2013
# last date in dataset - 6th Jul 2021
# When the calendars load we want to ensure that the default dates selected are within the date range above
# we can do this by setting variables to store suitable default values for sellCalendar and buyCalendar.
self.sellCalendarDefaultDate = sorted(self.data['BTC'].keys())[-1] # Accessing the last element of a python list is explained with method 2 on https://www.geeksforgeeks.org/python-how-to-get-the-last-element-of-list/
print("self.sellCalendarStartDate",self.sellCalendarDefaultDate)
#self.buyCalendarDefaultDate
#print("self.buyCalendarStartDate", self.buyCalendarDefaultDate)

# create QLabel for CrytoCurrency purchased

# create QComboBox and populate it with a list of cryptocurrencies

# create CalendarWidgets for the selection of purchase and sell dates

# create QSpinBox to select the CrytoCurrency quantity purchased

# create QLabels to show the CrytoCurrency purchase total

# create QLabels to show the CrytoCurrency sell total

# create QLabels to show the CrytoCurrency profit total

# initialize the layout - 6 rows to start

# row 0 - CrytoCurrency selection

# row 1 - quantity selection

# row 2 - purchase date selection

# row 3 - display purchase total

# row 4 - sell date selection

# row 5 - display sell total

# row 6 - display sell total

# set the calendar values
# purchase: two weeks before most recent
# sell: most recent

# connecting signals to slots to that a change in one control updates the UI

# set the window title
# update the UI


def updateUi(self):
'''
This requires substantial development
Updates the Ui when control values are changed, should also be called when the app initializes
:return:
'''
try:
print("")
# get selected dates from calendars

# perform necessary calculations to calculate totals

# update the label displaying totals
except Exception as e:
print(e)


################ YOU DO NOT HAVE TO EDIT CODE BELOW THIS POINT ########################################################

def make_data(self):
'''
This code is complete
Data source is derived from https://www.kaggle.com/sudalairajkumar/cryptocurrencypricehistory but use the provided file to avoid confusion

Stock -> Date -> Close
BTC -> 29/04/2013 -> 144.54
-> 30/04/2013 -> 139
.....
-> 06/07/2021 -> 34235.19345

...

Helpful tutorials to understand this
- https://stackoverflow.com/questions/482410/how-do-i-convert-a-string-to-a-double-in-python
- nested dictionaries https://stackoverflow.com/questions/16333296/how-do-you-create-nested-dict-in-python
- https://www.tutorialspoint.com/python3/python_strings.htm
:return: a dictionary of dictionaries
'''
file = open(".//combined.csv","r") # open a CSV file for reading https://docs.python.org/3/library/functions.html#open
data = {} # empty data dictionary
file_rows = [] # empty list of file rows
# add rows to the file_rows list
for row in file:
file_rows.append(row.strip()) # https://www.geeksforgeeks.org/python-string-strip-2/
print("len(file_rows):" + str(len(file_rows)))

# get the column headings of the CSV file
row0 = file_rows[0]
line = row0.split(",")
column_headings = line
print(column_headings)

# get the unique list of CrytoCurrencies from the CSV file
non_unique_cryptos = []
file_rows_from_row1_to_end = file_rows[1:len(file_rows) - 1]
for row in file_rows_from_row1_to_end:
line = row.split(",")
non_unique_cryptos.append(line[6])
cryptos = self.unique(non_unique_cryptos)
print("len(cryptos):" + str(len(cryptos)))
print("cryptos:" + str(cryptos))

# build the base dictionary of CryptoCurrencies
for crypto in cryptos:
data[crypto] = {}

# build the dictionary of dictionaries
for row in file_rows_from_row1_to_end:
line = row.split(",")
date = self.string_date_into_QDate(line[0])
crypto = line[6]
close_price = line[4]
#include error handling code if close price is incorrect
data[crypto][date]= float(close_price)
print("len(data):",len(data))
return data


def string_date_into_QDate(self, date_String):
'''
This method is complete
Converts a data in a string format like that in a CSV file to QDate Objects for use with QCalendarWidget
:param date_String: data in a string format
:return:
'''
date_list = date_String.split("-")
date_QDate = QDate(int(date_list[0]), int(date_list[1]), int(date_list[2]))
return date_QDate


def unique(self, non_unique_list):
'''
This method is complete
Converts a list of non-unique values into a list of unique values
Developed from https://www.geeksforgeeks.org/python-get-unique-values-list/
:param non_unique_list: a list of non-unique values
:return: a list of unique values
'''
# intilize a null list
unique_list = []

# traverse for all elements
for x in non_unique_list:
# check if exists in unique_list or not
if x not in unique_list:
unique_list.append(x)
# print list
return unique_list

# This is complete
if __name__ == '__main__':

app = QApplication(sys.argv)
currency_converter = CryptoTradeProfitCalculator()
currency_converter.show()
sys.exit(app.exec_())

Language Python + PyQt5

Cyber Law Course Mock Trial Assignment:

•Goal of Mock Trial is to give a feel for what real trial is like

•We can’t have a real mock trial in an online class, but this project is designed to capture the feel of what you would do to prepare for/participate in a mock trial

•I encourage you to watch the recommended videos – especially example opening/closing statements

•Three Parts:

1.Written Direct Examination (90 Points)

2.Video Opening or Closing Statement (90 Points)

3.Peer Feedback (20 Points)

Written Direct Examination:

•Pick from among the 6 witnesses in the Mock Trial Packet

•Plaintiff’s Witnesses

–Dee Hawkins (Plaintiff/CTI Partner)

      –Cam Turner (Layton’s Former Friend)

      –Jordan King (Consultant for CTI)

•Defense Witnesses

      –Layton Pierce (Defendant/Teacher’s Pet Creator)

      –Shawn Newman (Venture Capitalist)

      –Alex Hart (Teacher/Advisor)

•Direct examination should include open-ended (non-leading) questions.

•Your questions should benefit the plaintiff if you pick a plaintiff’s witness or the defense if you pick a defense witness

•You should also include the anticipated answers to your questions.

•The goal of the direct examination is to get to the essential elements that you need from that witness to further the overall case. Don’t try to get through every element of the packet

•It’s okay to include information that doesn’t benefit your case if it would be likely to come up into trial and you want to present it first to show to the jury that you’re not hiding it.

•Follow the template

•Consult the rubric and make sure you meet all the elements

•Four page limit

•Question/answer format

•Make sure you introduce at least the required exhibits for your witness

Video Opening or Closing

•Decide whether you would like to represent the plaintiff or the defendant (doesn’t have to be the same as what you did for the direct)

•Decide whether you would like to do an opening or closing statement

•Wear professional attire to the extent that you can. If in good faith you cannot wear a business suit, please do your best to come as close as you can

•Try to get the video recorder far enough away that you can be seen from at least the waist up

•Upload the video as an unlisted video to You Tube and post a link on the discussion board (other options are fine but if you upload to a different place and I cannot access it by the due date you will lose points)

•Consult the rubric and make sure you meet all the elements

•Three minute limit

•Don’t just read your opening or closing statement

•Don’t make things up

•Recommend you review the entire packet so you can draw conclusions from the whole of the evidence

•Ask the jury what you want them to do – “find the defendant liable on both counts” or “answer both questions on the jury form “no” or something similar

•Describe the burden of proof – Note, in this case there are two different burdens of proof, preponderance of the evidence for charge one and clear and convincing evidence for charge two – make sure you explain that in your video

Peer Feedback

•Provide feedback to two of your peers on their video submissions

•The first peer you provide feedback to should be the post immediately before yours (unless you are first and then just pick two others at random)

•Include at least one strength of the presentation or argument

•Include at least one opportunity to improve or recommendation for information that could have been included

•Write your feedback to be constructive and coherent – don’t just say “nice job bro” instead say “I really liked your eye contact” or “I like how you explained the burden of proof.”

Bottom Line

•Read the rubric and make sure you don’t leave any points on the table.

•Read the packet thoroughly. There are lots of hidden and cool facts in there.

•The time and page limits are LIMITS not minimums. I will take points off if you go over.

•Have fun – this has been a really enjoyable project in my in-person classes and most online students have also reported enjoying it.

•One final note, this is the first time I’m using this particular mock trial packet. If you spot any errors or typos, please let me know.

Step by Step Solution

3.30 Rating (162 Votes )

There are 3 Steps involved in it

Step: 1

import sys from PyQt5QtCore import QDate from PyQt5QtWidgets import QLabel QComboBox QCalendarWidget QDialog QApplication QGridLayout QSpinBox from Py... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students explore these related Programming questions

Question

=+a) What are the factors they are testing?

Answered: 3 weeks ago

Question

W ha t are some unforeseen costs of ERP?

Answered: 3 weeks ago