Here are the specefications for the project. Please let me know if you need more
ID: 3728522 • Letter: H
Question
Here are the specefications for the project. Please let me know if you need more information or if there's anything I can help with. Thanks!
The assignment's sumbmission requires 5 seperate python files that are specefied below:
Submission:
fileMatchingFuncs.py,
fileMatching.py,
funcsTests.py,
sorted_oldMaster.dat, and
newMaster.dat.
Program Description:
In commercial data processing, it’s common to have several files in each system. In an accounts receivable system, for example, there is generally a master file containing detailed information about each customer such as the customer’s name, address, telephone number, outstanding balance, credit limit, discount terms, contract arrangements and possibly a condensed history of recent purchases and cash payments. In this program, we only stored the customers’ account number, customers’ first and last name, customer’s balance, customers’ phone number, and customers’ city.
As transactions occur (i.e., sales are made and cash payments arrive in the mail), they’re entered into a file. At the end of each business period (i.e., a month for some companies, a week for others and a day in some cases) the file of transactions (called "transaction.dat") is applied to the master file (called "oldMaster.dat"), thus updating each account's record of purchases and payments. After each of these updates, the master file is rewritten as a new file ("newMaster.dat"), which is then used at the end of the next business period to begin the updating process again.
File-matching programs must deal with certain problems that do not exist in single-file programs. For example, a match does not always occur. A customer on the master file might not have made any purchases or cash payments in the current business period, and therefore no record for this customer will appear on the transaction file. Similarly, a customer who did make some purchases or cash payments might have just moved to this community and the company may not have had a chance to create a master record for this customer.
Use the account number on each file as the record key for matching purposes. The oldMaster.dat is not ordered. You need to read the file and generate a sequential file, which is
sorted in increasing account number order. This sequential file will be sorted_oldMaster.dat. The transaction.dat file has records of account numbers and value.
When a match occurs (i.e., records with the same account number appear on both the master file and the transaction file), add the dollar amount on the transaction file to the current balance on the master file and write the "newMaster.dat" record. (Assume that purchases are indicated by positive amounts on the transaction file, and that payments are indicated by negative amounts.)
When there is a master record for a particular account but no corresponding transaction record, merely write the master record to "newMaster.dat". When there is a transaction record but no corresponding master record, print the message "Unmatched transaction record for account number ..." (fill in the account number from the transaction record)
For example:
Unmatched transaction record for account 900
Explanation / Answer
funcsTests.py
-----------------------------------------------------
import unittest
from fileMatchingFuncs import *
class TestCases (unittest.TestCase):
# Add test functions here
def test_getTextFileInfo(self):
self.assertEqual(getTextFileInfo('oldMaster.dat'), [
['100', 'Alan', 'Jones', '348.17', '8053564820', 'SLO'],
['700', 'Suzy', 'Green', '-14.22', '8052586912', 'SLO'],
['300', 'Mary', 'Smith', '27.19', '8057901237', 'Santa_Maria'],
['800', 'Mike', 'Rosen', '-104.58', '8051200891', 'Pismo_Beach'],
['500', 'Sam', 'Sharp', '0.00', '8052348970', 'SLO'],
['200', 'Adam', 'Wise', '100.00', '8059867128', 'SLO'],
['120', 'Ford', 'Strong', '90.00', '8051155329', 'SLO'],
['340', 'Lena', 'Sharp', '70.00', '8058561859', 'SLO'],
['600', 'Nicol', 'Green', '-20.00', '8058875571', 'SLO']])
self.assertEqual(getTextFileInfo('newIn2.dat'), [
['101', 'Ayssa', 'Sherman', '240.22', '8051298970', 'SLO'],
['127', 'Robbin', 'Perry', '-59.37', '8051234820', 'Arroyo_Grande'],
['210', 'Nolan', 'Woodbreak', '327.22', '8059855128', 'SLO'],
['245', 'Jeffry', 'Smith', '15.31', '8057901000', 'Santa_Maria'],
['715', 'Erick', 'Dowsy', '123.22', '8052006912', 'Atascadero'],
['788', 'Laris', 'Nolan', '697.86', '805125789', 'Paso_Robles']])
self.assertEqual(getTextFileInfo('newIn3.dat'), [
['010', 'Jo', 'Lee', '-185.02', '8052348970', 'Santa_Maria'],
['103', 'Kent', 'Lee', '1698.48', '8123464820', 'SLO'],
['111', 'Shay', 'Jam', '143.02', '8051200891', 'Santa_Rose'],
['555', 'Renei', 'McCart', '100.59', '8057901237', 'Santa_Rose'],
['808', 'Sara', 'Grave', '-83.73', '8052586912', 'Morro_Bay']])
def test_sortAccountNumber(self):
self.assertEqual(sortAccountNumber(getTextFileInfo('oldMaster.dat')), [
100, 120, 200, 300, 340, 500, 600, 700, 800])
self.assertEqual(sortAccountNumber(getTextFileInfo('newIn2.dat')), [
101, 127, 210, 245, 715, 788])
self.assertEqual(sortAccountNumber(getTextFileInfo('newIn3.dat')), [10, 103, 111, 555, 808])
def test_sortTextFileInfo(self):
self.assertEqual(sortTextFileInfo(getTextFileInfo('oldMaster.dat')), [
['100', 'Alan', 'Jones', '348.17', '8053564820', 'SLO'],
['120', 'Ford', 'Strong', '90.00', '8051155329', 'SLO'],
['200', 'Adam', 'Wise', '100.00', '8059867128', 'SLO'],
['300', 'Mary', 'Smith', '27.19', '8057901237', 'Santa_Maria'],
['340', 'Lena', 'Sharp', '70.00', '8058561859', 'SLO'],
['500', 'Sam', 'Sharp', '0.00', '8052348970', 'SLO'],
['600', 'Nicol', 'Green', '-20.00', '8058875571', 'SLO'],
['700', 'Suzy', 'Green', '-14.22', '8052586912', 'SLO'],
['800', 'Mike', 'Rosen', '-104.58', '8051200891', 'Pismo_Beach']])
self.assertEqual(sortTextFileInfo(getTextFileInfo('newIn2.dat')), [
['101', 'Ayssa', 'Sherman', '240.22', '8051298970', 'SLO'],
['127', 'Robbin', 'Perry', '-59.37', '8051234820', 'Arroyo_Grande'],
['210', 'Nolan', 'Woodbreak', '327.22', '8059855128', 'SLO'],
['245', 'Jeffry', 'Smith', '15.31', '8057901000', 'Santa_Maria'],
['715', 'Erick', 'Dowsy', '123.22', '8052006912', 'Atascadero'],
['788', 'Laris', 'Nolan', '697.86', '805125789', 'Paso_Robles']])
self.assertEqual(sortTextFileInfo(getTextFileInfo('newIn3.dat')), [
['010', 'Jo', 'Lee', '-185.02', '8052348970', 'Santa_Maria'],
['103', 'Kent', 'Lee', '1698.48', '8123464820', 'SLO'],
['111', 'Shay', 'Jam', '143.02', '8051200891', 'Santa_Rose'],
['555', 'Renei', 'McCart', '100.59', '8057901237', 'Santa_Rose'],
['808', 'Sara', 'Grave', '-83.73', '8052586912', 'Morro_Bay']])
def test_matchTransaction(self):
self.assertEqual(matchTransaction(sortTextFileInfo(getTextFileInfo('oldMaster.dat')),
getTextFileInfo('transaction.dat'),
sortAccountNumber(getTextFileInfo('oldMaster.dat'))),
[[400, 900],
[['100', 'Alan', 'Jones', '445.48', '8053564820', 'SLO'],
['120', 'Ford', 'Strong', '190.17', '8051155329', 'SLO'],
['200', 'Adam', 'Wise', '350.00', '8059867128', 'SLO'],
['300', 'Mary', 'Smith', '589.30', '8057901237', 'Santa_Maria'],
['340', 'Lena', 'Sharp', '70.00', '8058561859', 'SLO'],
['500', 'Sam', 'Sharp', '-55.25', '8052348970', 'SLO'],
['600', 'Nicol', 'Green', '-20.00', '8058875571', 'SLO'],
['700', 'Suzy', 'Green', '410.78', '8052586912', 'SLO'],
['800', 'Mike', 'Rosen', '-104.58', '8051200891', 'Pismo_Beach']]])
self.assertEqual(matchTransaction(sortTextFileInfo(getTextFileInfo('newIn2.dat')),
getTextFileInfo('trans2.dat'),
sortAccountNumber(getTextFileInfo('newIn2.dat'))),
[[201],
[['101', 'Ayssa', 'Sherman', '240.22', '8051298970', 'SLO'],
['127', 'Robbin', 'Perry', '-40.37', '8051234820', 'Arroyo_Grande'],
['210', 'Nolan', 'Woodbreak', '534.36', '8059855128', 'SLO'],
['245', 'Jeffry', 'Smith', '15.31', '8057901000', 'Santa_Maria'],
['715', 'Erick', 'Dowsy', '123.22', '8052006912', 'Atascadero'],
['788', 'Laris', 'Nolan', '1409.97', '805125789', 'Paso_Robles']]])
self.assertEqual(matchTransaction(sortTextFileInfo(getTextFileInfo('newIn3.dat')),
getTextFileInfo('trans3.dat'),
sortAccountNumber(getTextFileInfo('newIn3.dat'))),
[[100],
[['010', 'Jo', 'Lee', '-210.94', '8052348970', 'Santa_Maria'],
['103', 'Kent', 'Lee', '2847.98', '8123464820', 'SLO'],
['111', 'Shay', 'Jam', '266.46', '8051200891', 'Santa_Rose'],
['555', 'Renei', 'McCart', '100.59', '8057901237', 'Santa_Rose'],
['808', 'Sara', 'Grave', '-43.17', '8052586912', 'Morro_Bay']]])
# Run the unit tests.
if __name__ == '__main__':
unittest.main()
------------------------------------------------------------------------------------------------------
fileMatchingFuncs.py
-------------------------------------------------------------
# Function that opens the text file, and parses it to be
# used for other functions
def getTextFileInfo(fileName):
fin = open(fileName)
textFileInfoList = []
for line in fin:
words = line.split()
textFileInfoList.append(words)
fin.close()
return textFileInfoList
# This function returns a list of just account numbers
def sortAccountNumber(textFileInfoList):
sortedAccountNumberList = []
i = 0
while i < len(textFileInfoList):
unsortedAccountNumber = int(textFileInfoList[i][0])
sortedAccountNumberList.append(unsortedAccountNumber)
i += 1
sortedAccountNumberList.sort()
return sortedAccountNumberList
# This function sorts all of the account data by
# account number
def sortTextFileInfo(textFileInfoList):
sortTextFileInfoList = textFileInfoList
sortTextFileInfoList.sort(key=lambda a: a[0])
return sortTextFileInfoList
# This function creates the sorted old master file
def createOldMaster(sortTextFileInfoList):
fout = open('sorted_oldMaster.dat', 'w')
k = 0
while k in range(len(sortTextFileInfoList)):
tempString = '{:4} {:6} {:11} {:10} {:15} {:12}'.format(
sortTextFileInfoList[k][0],
sortTextFileInfoList[k][1],
sortTextFileInfoList[k][2],
sortTextFileInfoList[k][3],
sortTextFileInfoList[k][4],
sortTextFileInfoList[k][5])
fout.write('{} '.format(tempString))
k += 1
fout.close()
# The function creates the new master file with the
# unmatched transactions
def createNewMaster(sortTextFileInfoList):
fout = open('newMaster.dat', 'w')
k = 0
while k in range(len(sortTextFileInfoList[1])):
tempString = '{:4} {:6} {:11} {:10} {:15} {:12}'.format(
sortTextFileInfoList[1][k][0],
sortTextFileInfoList[1][k][1],
sortTextFileInfoList[1][k][2],
sortTextFileInfoList[1][k][3],
sortTextFileInfoList[1][k][4],
sortTextFileInfoList[1][k][5])
fout.write('{} '.format(tempString))
k += 1
for i in range(len(sortTextFileInfoList[0])):
fout.write('Unmatched transaction record for account {} '.format(
sortTextFileInfoList[0][i]))
fout.close()
# This function matches transactions to the master file
def matchTransaction(old_sorted_list, transactionFile, accountNumbers):
notFound = []
for i in range(len(old_sorted_list)):
for j in range(len(transactionFile)):
if transactionFile[j][0] == old_sorted_list[i][0]:
old_balance = float(old_sorted_list[i][3])
add_balance = float(transactionFile[j][1])
old_sorted_list[i][3] = "{:.2f}".format(
old_balance + add_balance)
else:
if int(transactionFile[j][0]) not in accountNumbers:
notFound.append(int(transactionFile[j][0]))
accountNumbers.append(int(transactionFile[j][0]))
masterData = [notFound, old_sorted_list]
return(masterData)
----------------------------------------------------------------------------------------------
fileMatching.py
---------------------------------------
from fileMatchingFuncs import *
# Main Function
def main():
fileData = getTextFileInfo('oldMaster.dat')
accountNumbers = sortAccountNumber(fileData)
sortedData = sortTextFileInfo(fileData)
createOldMaster(sortedData)
transactionData = getTextFileInfo('transaction.dat')
sortedData = matchTransaction(sortedData, transactionData, accountNumbers)
createNewMaster(sortedData)
# Calls main function
if __name__ == "__main__":
main()
-----------------------------------------------------------------------------------------------------
sorted_oldMaster.dat
---------------------------------
100 Alan Jones 348.17 8053564820 SLO
120 Ford Strong 90.00 8051155329 SLO
200 Adam Wise 100.00 8059867128 SLO
300 Mary Smith 27.19 8057901237 Santa_Maria
340 Lena Sharp 70.00 8058561859 SLO
500 Sam Sharp 0.00 8052348970 SLO
600 Nicol Green -20.00 8058875571 SLO
700 Suzy Green -14.22 8052586912 SLO
800 Mike Rosen -104.58 8051200891 Pismo_Beach
--------------------------------------------------------------------------------------------------
newMaster.dat
---------------------------------------
100 Alan Jones 445.48 8053564820 SLO
120 Ford Strong 190.17 8051155329 SLO
200 Adam Wise 350.00 8059867128 SLO
300 Mary Smith 589.30 8057901237 Santa_Maria
340 Lena Sharp 70.00 8058561859 SLO
500 Sam Sharp -55.25 8052348970 SLO
600 Nicol Green -20.00 8058875571 SLO
700 Suzy Green 410.78 8052586912 SLO
800 Mike Rosen -104.58 8051200891 Pismo_Beach
Unmatched transaction record for account 400
Unmatched transaction record for account 900
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.