-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram 2.rkt
More file actions
138 lines (114 loc) · 4.53 KB
/
Program 2.rkt
File metadata and controls
138 lines (114 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#lang racket/gui
(require racket/system)
(require text-table)
(require csv-reading)
;; Define a function to read the CSV file into a list of records
(define (data-path symbol period)
(build-path "Video Game Sales" period (string-append symbol ".csv")))
;; Function to filter games list by name (case-insensitive)
(define (filter-by-name games-list name)
(filter (lambda (game) (string-ci=? (second game) name)) games-list))
;; Function to filter games list by date range
(define (filter-by-date games-list start-year end-year)
(let ([start (min start-year end-year)]
[end (max start-year end-year)])
(filter (lambda (game)
(let ([year (string->number (fifth game))])
(and (<= start year) (<= year end))))
games-list)))
;; Function to filter games list by publisher (case-insensitive, partial match)
(define (filter-by-publisher games-list publisher)
(filter (lambda (game)
(string-contains? (string-downcase (seventh game)) (string-downcase publisher)))
games-list))
;; Function to filter games list by region sales
;; Assumes 'region' is one of: 'North America', 'Europe', 'Japan', 'Rest of World', 'Global'
(define (filter-by-region games-list region)
(let ([index (case region
[('North America) 8]
[('Europe) 9]
[('Japan) 10]
[('Rest of World) 11]
[('Global) 12]
[else (error "Invalid region")])])
(filter (lambda (game) (> (string->number (list-ref game index)) 0)) games-list)))
;; Function to filter games list by genre
(define (filter-by-genre games-list genre)
(filter (lambda (game) (string-ci=? (sixth game) genre)) games-list))
;; Sorting function placeholder (to be implemented)
(define (sort-games games-list sort-by)
(displayln "This function has yet to be implemented")
;; Implement sorting logic based on 'sort-by' criteria ('rank' or 'review')
games-list)
;; Main function to handle user interaction (to be implemented)
(define (main)
;; Read the CSV data file
;; Implement user interaction for entering search criteria
(define main-frame
(new frame%
[label "Video Game Sales Program"]
[width 800]
[height 600]))
(define msg
(new message%
[parent main-frame]
[auto-resize #t]
[label "Welcome to the Video Game Sales program! To begin, specify any 3 of the following criteria to better filter the list to the relevant information for your needs"]))
(define control-panel1
(new horizontal-panel%
[parent main-frame]))
(define control-panel2
(new horizontal-panel%
[parent main-frame]))
(define control-panel3
(new horizontal-panel%
[parent main-frame]))
(define control-panel4
(new horizontal-panel%
[parent main-frame]))
(define control-panel5
(new horizontal-panel%
[parent main-frame]))
(new button%
[parent control-panel1]
[label "Name"]
[callback (λ (button event)
())])
(define text-name
(new text-field%
[parent control-panel1]
[label "Video Game Name: "]
[stretchable-width #f]
[init-value ""]))
(new button%
[parent control-panel2]
[label "Date"]
[callback (λ (button event)
(send ))])
(new button%
[parent control-panel3]
[label "Publisher"]
[callback (λ (button event)
(send ))])
(new button%
[parent control-panel4]
[label "Region"]
[callback (λ (button event)
(send ))])
(new button%
[parent control-panel5]
[label "Genre"]
[callback (λ (button event)
(send ))])
(send main-frame show #t)
(displayln "Welcome to the Video Game Sales program! To begin, specify any 3 of the following criteria to better filter the list to the relevant information for your needs\n")
(displayln "Name - case insensitive, but spelling counts")
(displayln "Date - requires beginning and end years, can also have both beginning and end be in 1 year")
(displayln "Publisher - case insensitive, but partial match is feasible (refer to full publisher name rather than stock symbol)")
(displayln "Region - specified by North America, Europe, Japan, Other, or Global")
(displayln "Genre - must use categories provided within the set")
#|Apply filters based on user input
Optionally sort the filtered list
Display the results to the user
Repeat or exit based on user input|#
)