Your Name commited on
Commit
0480ef8
·
0 Parent(s):

Initial commit - First working version of dashboard

Browse files
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ .Rproj.user
2
+ .Rhistory
3
+ .RData
4
+ .DS_Store
5
+ .Renviron
Bid_SalesAnalysisByEstimatorByMonth_121125.csv ADDED
@@ -0,0 +1,425 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ EmployeeShort,Estimator,MoYear,AmtBid,QtyBid,AmtBooked,QtyBooked
2
+ BD,Don Barrett,19-06,"1,035.00",1,"1,035.00",1
3
+ BN,Bryan Narvaez,25-03,"193,423.81",6,"17,869.11",1
4
+ BN,Bryan Narvaez,25-02,"364,963.84",6,0.00,0
5
+ BN,Bryan Narvaez,25-01,"539,477.56",7,0.00,0
6
+ BN,Bryan Narvaez,24-12,"204,376.05",4,0.00,0
7
+ BN,Bryan Narvaez,24-11,"317,709.47",5,"101,084.36",1
8
+ BN,Bryan Narvaez,24-10,"256,154.16",4,0.00,0
9
+ BN,Bryan Narvaez,24-09,"617,123.27",3,0.00,0
10
+ BR,Bob Redondo,17-09,"118,465.25",1,"118,465.25",1
11
+ BR,Bob Redondo,16-10,746.00,1,0.00,0
12
+ CN,Chris Napier,23-06,"18,949.20",1,"18,949.20",1
13
+ DB,Danny Baca,25-12,"97,051.67",7,0.00,0
14
+ DB,Danny Baca,25-11,"331,954.60",10,"1,359.00",1
15
+ EO,Eric Orton,13-09,"4,149.62",1,"4,149.62",1
16
+ EO,Eric Orton,13-08,"103,046.09",6,"31,457.13",3
17
+ EO,Eric Orton,13-07,"249,600.58",18,0.00,0
18
+ EO,Eric Orton,13-06,"166,143.32",19,"35,726.71",2
19
+ EO,Eric Orton,13-05,"178,202.94",19,"28,935.16",3
20
+ EO,Eric Orton,13-04,"280,645.98",22,"83,928.74",3
21
+ EO,Eric Orton,13-03,"199,232.39",24,"25,304.02",2
22
+ EO,Eric Orton,13-02,"303,122.96",15,"2,079.66",1
23
+ EO,Eric Orton,13-01,"44,378.42",4,"4,248.24",1
24
+ GW,Greg Webb,25-01,0.00,1,0.00,0
25
+ GW,Greg Webb,24-12,"183,719.00",2,0.00,0
26
+ IH,Isaak Hutchings,25-12,"390,955.96",8,0.00,0
27
+ IH,Isaak Hutchings,25-11,"133,851.19",5,"16,519.49",1
28
+ IH,Isaak Hutchings,25-10,"463,163.04",12,"19,177.78",1
29
+ IH,Isaak Hutchings,25-08,"38,921.79",2,0.00,0
30
+ IH,Isaak Hutchings,23-07,"42,375.48",4,"9,171.53",1
31
+ IH,Isaak Hutchings,23-06,"185,727.49",12,"4,086.45",1
32
+ JV,Jennifer Vice,25-05,"30,781.11",1,0.00,0
33
+ KF,Ken Frazer,16-04,"2,050.00",1,"2,050.00",1
34
+ KF,Ken Frazer,15-04,415.37,1,0.00,1
35
+ LH,Larry Howard,25-12,"310,801.18",8,0.00,0
36
+ LH,Larry Howard,25-11,"358,815.28",14,"74,408.24",5
37
+ LH,Larry Howard,25-10,"537,835.10",19,"204,845.68",4
38
+ LH,Larry Howard,25-09,"1,129,237.28",16,"217,831.99",4
39
+ LH,Larry Howard,25-08,"1,009,390.59",12,"32,233.26",2
40
+ LH,Larry Howard,25-07,"1,020,613.77",19,"76,510.32",3
41
+ LH,Larry Howard,25-06,"405,418.26",21,"48,276.00",5
42
+ LH,Larry Howard,25-05,"1,309,231.48",15,"1,066,321.69",9
43
+ LH,Larry Howard,25-04,"925,815.29",23,"71,690.27",5
44
+ LH,Larry Howard,25-03,"738,268.45",20,"119,794.43",8
45
+ LH,Larry Howard,25-02,"532,021.54",15,"33,985.65",4
46
+ LH,Larry Howard,25-01,"583,440.71",16,"99,235.92",4
47
+ LH,Larry Howard,24-12,"693,052.31",11,"60,116.60",3
48
+ LH,Larry Howard,24-11,"684,935.98",14,"236,410.20",4
49
+ LH,Larry Howard,24-10,"1,706,308.27",27,"202,386.07",12
50
+ LH,Larry Howard,24-09,"1,823,356.42",24,"438,596.15",6
51
+ LH,Larry Howard,24-08,"673,217.00",21,"76,548.51",7
52
+ LH,Larry Howard,24-07,"817,813.23",17,"185,917.46",7
53
+ LH,Larry Howard,24-06,"438,032.70",15,"63,557.72",4
54
+ LH,Larry Howard,24-05,"1,229,316.91",25,"186,390.27",7
55
+ LH,Larry Howard,24-04,"621,911.09",17,"73,114.72",5
56
+ LH,Larry Howard,24-03,"926,357.06",19,"78,296.41",3
57
+ LH,Larry Howard,24-02,"416,270.93",10,"58,862.23",3
58
+ LH,Larry Howard,24-01,"360,373.96",10,"115,743.80",6
59
+ LH,Larry Howard,23-12,"206,998.68",14,"37,709.88",4
60
+ LH,Larry Howard,23-11,"746,057.23",16,"55,229.92",2
61
+ LH,Larry Howard,23-10,"625,822.87",19,"123,203.67",5
62
+ LH,Larry Howard,23-09,"337,090.24",12,"80,500.60",4
63
+ LH,Larry Howard,23-08,"684,622.55",19,"454,747.68",10
64
+ LH,Larry Howard,23-07,"553,799.18",22,"53,676.14",6
65
+ LH,Larry Howard,23-06,"1,245,894.26",18,"49,959.12",2
66
+ LH,Larry Howard,23-05,"912,732.06",18,"455,755.46",7
67
+ LH,Larry Howard,23-04,"716,452.49",17,"330,389.07",5
68
+ LH,Larry Howard,23-03,"526,605.78",15,"17,844.15",2
69
+ LH,Larry Howard,23-02,"986,343.94",27,"133,547.46",8
70
+ LH,Larry Howard,23-01,"583,109.11",12,"94,679.56",5
71
+ LH,Larry Howard,22-12,"917,411.15",18,"225,353.27",5
72
+ LH,Larry Howard,22-11,"513,783.39",15,"60,331.16",2
73
+ LH,Larry Howard,22-10,"1,297,124.05",26,"348,679.56",11
74
+ LH,Larry Howard,22-09,"875,551.02",19,"266,003.06",6
75
+ LH,Larry Howard,22-08,"1,254,980.29",19,"191,781.51",9
76
+ LH,Larry Howard,22-07,"816,277.00",25,"50,369.18",9
77
+ LH,Larry Howard,22-06,"928,804.74",18,"175,001.15",6
78
+ LH,Larry Howard,22-05,"1,369,598.01",26,"209,496.55",10
79
+ LH,Larry Howard,22-04,"777,868.32",26,"145,974.79",11
80
+ LH,Larry Howard,22-03,"792,729.17",16,"544,796.12",7
81
+ LH,Larry Howard,22-02,"813,841.57",20,"313,941.96",9
82
+ LH,Larry Howard,22-01,"695,623.09",25,"265,858.00",7
83
+ LH,Larry Howard,21-12,"645,342.20",14,"52,701.26",4
84
+ LH,Larry Howard,21-11,"694,232.84",20,"303,513.53",11
85
+ LH,Larry Howard,21-10,"811,760.38",21,"98,072.21",4
86
+ LH,Larry Howard,21-09,"746,049.27",19,"342,961.53",6
87
+ LH,Larry Howard,21-08,"1,113,937.92",24,"424,868.12",9
88
+ LH,Larry Howard,21-07,"845,225.09",20,"73,754.84",6
89
+ LH,Larry Howard,21-06,"961,884.83",27,"273,646.06",9
90
+ LH,Larry Howard,21-05,"886,930.83",21,"198,322.88",6
91
+ LH,Larry Howard,21-04,"1,529,294.31",35,"935,475.34",16
92
+ LH,Larry Howard,21-03,"1,195,046.67",27,"248,766.53",7
93
+ LH,Larry Howard,21-02,"1,381,066.73",37,"536,774.18",17
94
+ LH,Larry Howard,21-01,"1,312,842.29",23,"474,288.80",7
95
+ LH,Larry Howard,20-12,"1,074,924.65",30,"210,793.01",7
96
+ LH,Larry Howard,20-11,"1,121,715.47",21,"80,467.65",3
97
+ LH,Larry Howard,20-10,"1,071,132.81",33,"342,407.27",12
98
+ LH,Larry Howard,20-09,"1,275,981.79",39,"311,007.53",14
99
+ LH,Larry Howard,20-08,"975,002.75",24,"642,838.61",11
100
+ LH,Larry Howard,20-07,"760,126.40",30,"325,531.83",16
101
+ LH,Larry Howard,20-06,"1,329,384.18",36,"258,339.46",8
102
+ LH,Larry Howard,20-05,"886,766.21",21,"159,883.17",6
103
+ LH,Larry Howard,20-04,"1,404,509.17",34,"392,978.98",9
104
+ LH,Larry Howard,20-03,"974,656.86",31,"204,318.69",10
105
+ LH,Larry Howard,20-02,"529,015.71",21,"274,023.37",9
106
+ LH,Larry Howard,20-01,"971,596.80",30,"408,316.07",12
107
+ LH,Larry Howard,19-12,"666,055.62",19,"344,591.31",8
108
+ LH,Larry Howard,19-11,"781,767.49",28,"422,911.28",15
109
+ LH,Larry Howard,19-10,"1,373,050.07",38,"273,875.24",10
110
+ LH,Larry Howard,19-09,"444,503.97",22,"136,598.61",11
111
+ LH,Larry Howard,19-08,"875,657.39",24,"139,892.26",8
112
+ LH,Larry Howard,19-07,"520,484.50",22,"224,572.06",9
113
+ LH,Larry Howard,19-06,"748,809.73",27,"128,790.37",8
114
+ LH,Larry Howard,19-05,"894,348.72",31,"592,594.03",16
115
+ LH,Larry Howard,19-04,"1,341,578.52",30,"303,598.73",12
116
+ LH,Larry Howard,19-03,"1,078,799.47",25,"102,092.71",7
117
+ LH,Larry Howard,19-02,"677,968.44",20,"213,649.91",8
118
+ LH,Larry Howard,19-01,"751,180.28",25,"166,562.78",10
119
+ LH,Larry Howard,18-12,"354,975.38",10,"118,676.27",3
120
+ LH,Larry Howard,18-11,"655,145.34",25,"94,104.03",8
121
+ LH,Larry Howard,18-10,"867,933.87",28,"350,998.60",12
122
+ LH,Larry Howard,18-09,"811,446.79",24,"244,483.10",10
123
+ LH,Larry Howard,18-08,"820,918.37",25,"543,408.15",13
124
+ LH,Larry Howard,18-07,"1,163,901.46",28,"376,735.14",11
125
+ LH,Larry Howard,18-06,"1,051,601.14",25,"193,581.17",10
126
+ LH,Larry Howard,18-05,"774,233.43",29,"163,822.43",13
127
+ LH,Larry Howard,18-04,"846,234.44",26,"367,237.83",12
128
+ LH,Larry Howard,18-03,"927,353.09",26,"178,502.25",9
129
+ LH,Larry Howard,18-02,"1,058,955.03",26,"423,831.58",9
130
+ LH,Larry Howard,18-01,"744,301.11",30,"333,158.83",11
131
+ LH,Larry Howard,17-12,"764,676.08",24,"162,576.08",7
132
+ LH,Larry Howard,17-11,"1,033,418.63",32,"104,838.49",5
133
+ LH,Larry Howard,17-10,"570,407.98",28,"286,438.93",9
134
+ LH,Larry Howard,17-09,"659,177.73",31,"211,671.33",13
135
+ LH,Larry Howard,17-08,"796,884.25",31,"67,496.86",7
136
+ LH,Larry Howard,17-07,"819,764.02",23,"74,681.58",5
137
+ LH,Larry Howard,17-06,"877,236.10",35,"442,208.29",12
138
+ LH,Larry Howard,17-05,"1,020,562.12",31,"182,788.22",6
139
+ LH,Larry Howard,17-04,"1,785,013.21",50,"641,503.66",19
140
+ LH,Larry Howard,17-03,"836,867.02",39,"292,872.73",14
141
+ LH,Larry Howard,17-02,"720,109.98",27,"193,744.47",12
142
+ LH,Larry Howard,17-01,"750,681.34",30,"81,454.13",5
143
+ LH,Larry Howard,16-12,"942,889.37",33,"331,832.15",16
144
+ LH,Larry Howard,16-11,"527,014.06",27,"183,392.82",10
145
+ LH,Larry Howard,16-10,"899,333.55",31,"90,692.54",4
146
+ LH,Larry Howard,16-09,"635,193.81",23,"67,059.77",5
147
+ LH,Larry Howard,16-08,"1,016,803.64",37,"204,029.69",13
148
+ LH,Larry Howard,16-07,"626,092.73",28,"334,624.63",9
149
+ LH,Larry Howard,16-06,"1,065,106.56",39,"246,359.12",11
150
+ LH,Larry Howard,16-05,"735,823.76",35,"318,345.93",12
151
+ LH,Larry Howard,16-04,"1,080,274.31",27,"73,721.14",5
152
+ LH,Larry Howard,16-03,"1,246,955.31",33,"107,584.69",9
153
+ LH,Larry Howard,16-02,"606,063.72",24,"186,513.30",9
154
+ LH,Larry Howard,16-01,"656,198.43",31,"312,168.82",12
155
+ LH,Larry Howard,15-12,"618,444.39",24,"242,228.19",9
156
+ LH,Larry Howard,15-11,"885,168.15",26,"441,237.32",8
157
+ LH,Larry Howard,15-10,"820,061.19",31,"106,570.51",7
158
+ LH,Larry Howard,15-09,"745,734.01",42,"236,379.23",11
159
+ LH,Larry Howard,15-08,"993,172.13",30,"160,270.31",9
160
+ LH,Larry Howard,15-07,"679,679.30",34,"66,191.88",7
161
+ LH,Larry Howard,15-06,"853,484.10",37,"195,392.76",14
162
+ LH,Larry Howard,15-05,"720,670.15",30,"51,431.22",6
163
+ LH,Larry Howard,15-04,"867,792.87",30,"148,128.74",8
164
+ LH,Larry Howard,15-03,"476,256.89",35,"41,143.03",4
165
+ LH,Larry Howard,15-02,"418,086.18",27,"73,336.44",7
166
+ LH,Larry Howard,15-01,"504,792.42",20,"136,343.46",6
167
+ LH,Larry Howard,14-12,"663,979.51",31,"172,947.68",9
168
+ LH,Larry Howard,14-11,"666,296.84",24,"129,240.00",4
169
+ LH,Larry Howard,14-10,"740,606.09",39,"152,078.72",10
170
+ LH,Larry Howard,14-09,"1,671,877.93",42,"129,732.62",11
171
+ LH,Larry Howard,14-08,"622,304.67",33,"119,712.80",7
172
+ LH,Larry Howard,14-07,"435,470.78",23,"61,945.77",5
173
+ LH,Larry Howard,14-06,"791,631.31",38,"101,498.22",7
174
+ LH,Larry Howard,14-05,"464,128.38",32,"135,718.25",10
175
+ LH,Larry Howard,14-04,"695,277.13",27,"162,610.52",7
176
+ LH,Larry Howard,14-03,"768,293.72",36,"154,166.64",12
177
+ LH,Larry Howard,14-02,"350,523.29",28,"54,096.41",6
178
+ LH,Larry Howard,14-01,"584,601.25",40,"266,415.45",17
179
+ LH,Larry Howard,13-12,"607,432.88",38,"114,411.73",11
180
+ LH,Larry Howard,13-11,"304,581.07",25,"98,499.05",9
181
+ LH,Larry Howard,13-10,"345,409.86",31,"75,566.03",8
182
+ LH,Larry Howard,13-09,"430,340.83",33,"124,184.08",8
183
+ LH,Larry Howard,13-08,"570,839.46",22,"87,519.04",7
184
+ LH,Larry Howard,13-07,"1,437,216.34",22,"44,544.57",7
185
+ LH,Larry Howard,13-06,"1,230,056.74",27,"40,970.18",7
186
+ LH,Larry Howard,13-05,"662,341.34",27,"58,083.10",7
187
+ LH,Larry Howard,13-04,"579,490.89",35,"150,454.42",10
188
+ LH,Larry Howard,13-03,"305,024.91",21,"41,473.15",3
189
+ LH,Larry Howard,13-02,"230,314.17",18,"89,764.84",5
190
+ LH,Larry Howard,13-01,"436,368.80",27,"110,947.60",9
191
+ LH,Larry Howard,12-12,"119,320.35",10,"79,548.36",8
192
+ LH,Larry Howard,12-11,"117,243.39",9,"117,243.39",9
193
+ LH,Larry Howard,12-10,"81,577.63",8,"81,577.63",8
194
+ LH,Larry Howard,12-09,"92,126.69",7,"92,126.69",7
195
+ LH,Larry Howard,12-08,"23,660.46",3,"23,660.46",3
196
+ LH,Larry Howard,12-07,"46,276.40",5,"34,190.58",4
197
+ LH,Larry Howard,12-06,"489,237.27",30,"130,181.73",8
198
+ LH,Larry Howard,12-05,"356,884.57",35,"111,209.95",13
199
+ LH,Larry Howard,12-04,"659,341.71",27,"132,956.24",8
200
+ LH,Larry Howard,12-03,"335,192.62",25,"97,413.66",3
201
+ LH,Larry Howard,12-02,"258,080.81",20,"67,558.54",4
202
+ LH,Larry Howard,12-01,"157,696.15",10,"32,509.90",3
203
+ LH,Larry Howard,11-12,"100,118.53",6,"28,472.59",2
204
+ LH,Larry Howard,11-11,"287,775.09",8,"14,381.61",1
205
+ LH,Larry Howard,11-10,"54,075.81",4,"37,929.24",1
206
+ MH,Mathew Howard,25-12,"450,747.54",8,0.00,0
207
+ MH,Mathew Howard,25-11,"912,624.51",14,"4,732.54",1
208
+ MH,Mathew Howard,25-10,"898,052.42",13,"62,483.76",4
209
+ MH,Mathew Howard,25-09,"1,800,077.28",13,"664,966.57",2
210
+ MH,Mathew Howard,25-08,"889,880.75",13,"175,182.84",3
211
+ MH,Mathew Howard,25-07,"1,502,253.04",11,"302,946.49",4
212
+ MH,Mathew Howard,25-06,"901,348.89",19,"209,239.49",4
213
+ MH,Mathew Howard,25-05,"815,447.84",12,"176,321.87",4
214
+ MH,Mathew Howard,25-04,"851,831.85",11,"176,494.37",3
215
+ MH,Mathew Howard,25-03,"1,495,937.26",22,"92,737.98",3
216
+ MH,Mathew Howard,25-02,"1,217,173.69",19,"217,702.09",5
217
+ MH,Mathew Howard,25-01,"1,687,910.51",23,"243,725.12",5
218
+ MH,Mathew Howard,24-12,"763,221.37",15,"185,423.87",3
219
+ MH,Mathew Howard,24-11,"1,220,907.45",13,"5,774.68",1
220
+ MH,Mathew Howard,24-10,"681,688.94",12,0.00,0
221
+ MH,Mathew Howard,24-09,"867,691.50",16,"63,501.67",5
222
+ MH,Mathew Howard,24-08,"1,677,277.16",13,"114,554.41",5
223
+ MH,Mathew Howard,24-07,"541,736.78",10,"37,295.65",2
224
+ MH,Mathew Howard,24-06,"1,598,222.78",18,"284,760.08",3
225
+ MH,Mathew Howard,24-05,"1,105,155.38",17,"773,257.55",6
226
+ MH,Mathew Howard,24-04,"551,625.61",13,"270,601.01",6
227
+ MH,Mathew Howard,24-03,"837,893.91",13,"37,666.55",2
228
+ MH,Mathew Howard,24-02,"837,502.54",12,"98,018.49",3
229
+ MH,Mathew Howard,24-01,"608,504.44",9,"35,815.41",1
230
+ MH,Mathew Howard,23-12,"479,278.01",8,"25,560.11",3
231
+ MH,Mathew Howard,23-11,"739,635.52",9,0.00,1
232
+ MH,Mathew Howard,23-10,"876,498.20",18,"314,773.42",7
233
+ MH,Mathew Howard,23-09,"300,688.53",7,0.00,0
234
+ MH,Mathew Howard,23-08,"501,535.33",9,"98,358.18",2
235
+ MH,Mathew Howard,23-07,"490,308.32",6,"122,520.52",2
236
+ MH,Mathew Howard,23-06,"1,059,631.27",12,"44,622.48",3
237
+ MH,Mathew Howard,23-05,"1,122,749.54",9,"148,485.74",1
238
+ MH,Mathew Howard,23-04,"769,505.45",10,"28,844.98",1
239
+ MH,Mathew Howard,23-03,"750,332.74",11,"86,880.11",2
240
+ MH,Mathew Howard,23-02,"606,631.84",7,"152,778.03",2
241
+ MH,Mathew Howard,23-01,"477,150.08",7,"285,396.46",4
242
+ MH,Mathew Howard,22-12,"777,443.49",10,"105,904.81",2
243
+ MH,Mathew Howard,22-11,"1,147,065.01",10,"420,186.11",4
244
+ MH,Mathew Howard,22-10,"495,142.15",6,"113,111.57",2
245
+ MH,Mathew Howard,22-09,"877,136.00",11,"266,225.76",4
246
+ MH,Mathew Howard,22-08,"896,492.86",13,"149,512.75",4
247
+ MH,Mathew Howard,22-07,"269,997.83",6,"69,252.31",2
248
+ MH,Mathew Howard,22-06,"1,184,045.74",6,"198,124.81",2
249
+ MH,Mathew Howard,22-05,"750,761.43",8,"431,562.11",2
250
+ MH,Mathew Howard,22-04,"723,835.02",9,"341,704.19",3
251
+ MH,Mathew Howard,22-03,"396,062.36",5,"166,588.20",2
252
+ MH,Mathew Howard,22-02,"533,503.15",6,"49,679.69",1
253
+ MH,Mathew Howard,22-01,"79,150.63",2,"41,797.78",1
254
+ MH,Mathew Howard,21-12,"103,397.45",2,0.00,0
255
+ MH,Mathew Howard,21-11,"166,037.89",4,"11,283.38",1
256
+ MH,Mathew Howard,21-10,"382,308.64",6,"4,332.38",1
257
+ MH,Mathew Howard,21-09,"201,109.19",4,0.00,0
258
+ MH,Mathew Howard,21-08,"348,237.00",4,0.00,0
259
+ MH,Mathew Howard,21-07,"624,097.25",5,"497,819.39",3
260
+ MH,Mathew Howard,21-06,"259,763.37",4,"73,204.38",2
261
+ MH,Mathew Howard,21-05,"346,522.27",3,"346,522.27",3
262
+ MH,Mathew Howard,21-04,"21,864.69",1,"21,864.69",1
263
+ SB,Shane Bills,17-06,"8,065.76",1,"8,065.76",1
264
+ SC,Scot Carper,19-11,"6,932.34",1,"6,932.34",1
265
+ SC,Scot Carper,19-04,"42,806.89",1,"42,806.89",1
266
+ SC,Scot Carper,18-08,"4,177.00",1,"4,177.00",1
267
+ SC,Scot Carper,17-10,"3,664.00",2,"3,472.00",2
268
+ SC,Scot Carper,17-06,"7,426.00",1,0.00,0
269
+ SC,Scot Carper,16-10,"3,837.00",1,"3,837.00",1
270
+ SC,Scot Carper,16-05,"7,117.00",1,"7,117.00",1
271
+ SC,Scot Carper,16-04,"2,341.00",1,"2,341.00",1
272
+ SC,Scot Carper,15-07,"8,982.00",1,"8,982.00",1
273
+ SC,Scot Carper,15-06,"11,155.00",1,"11,155.00",1
274
+ SC,Scot Carper,15-05,"33,532.54",1,0.00,0
275
+ SC,Scot Carper,15-04,"11,313.00",1,"11,313.00",1
276
+ SC,Scot Carper,15-03,"26,707.06",1,0.00,0
277
+ SC,Scot Carper,15-02,"12,680.00",1,"12,680.00",1
278
+ SC,Scot Carper,14-09,"86,022.19",1,0.00,0
279
+ SC,Scot Carper,14-08,"13,212.51",1,"13,212.51",1
280
+ SC,Scot Carper,13-10,"8,789.98",2,"1,676.00",1
281
+ SH,Scott W. Hutchings,25-10,"18,069.47",2,"2,762.00",1
282
+ SH,Scott W. Hutchings,25-09,"2,967.63",2,"2,263.81",1
283
+ SH,Scott W. Hutchings,25-07,"2,244.91",1,"2,244.91",1
284
+ SH,Scott W. Hutchings,25-05,"95,415.23",1,"95,415.23",1
285
+ SH,Scott W. Hutchings,25-02,"2,945.44",1,"2,945.44",1
286
+ SH,Scott W. Hutchings,25-01,"8,719.00",3,0.00,2
287
+ SH,Scott W. Hutchings,24-12,"6,327.62",1,"6,327.62",1
288
+ SH,Scott W. Hutchings,24-07,0.00,1,0.00,1
289
+ SH,Scott W. Hutchings,24-06,"35,116.51",1,0.00,0
290
+ SH,Scott W. Hutchings,24-04,"1,057,001.27",1,"1,057,001.27",1
291
+ SH,Scott W. Hutchings,24-03,"130,322.21",1,0.00,0
292
+ SH,Scott W. Hutchings,24-01,0.00,2,0.00,2
293
+ SH,Scott W. Hutchings,23-11,"153,920.11",1,"153,920.11",1
294
+ SH,Scott W. Hutchings,23-01,0.00,1,0.00,1
295
+ SH,Scott W. Hutchings,22-07,"5,336.88",1,"5,336.88",1
296
+ SH,Scott W. Hutchings,22-05,"2,348.00",1,"2,348.00",1
297
+ SH,Scott W. Hutchings,22-03,9.00,1,9.00,1
298
+ SH,Scott W. Hutchings,22-01,2.00,2,2.00,2
299
+ SH,Scott W. Hutchings,21-09,"177,597.53",1,"177,597.53",1
300
+ SH,Scott W. Hutchings,21-07,"5,426.00",1,0.00,0
301
+ SH,Scott W. Hutchings,21-03,"57,109.30",3,"1,871.00",1
302
+ SH,Scott W. Hutchings,21-01,"5,234.50",5,"3,331.75",4
303
+ SH,Scott W. Hutchings,20-11,"3,820.00",1,"3,820.00",1
304
+ SH,Scott W. Hutchings,20-10,"1,722.50",1,"1,722.50",1
305
+ SH,Scott W. Hutchings,20-09,0.00,1,0.00,1
306
+ SH,Scott W. Hutchings,20-08,"1,556.00",1,"1,556.00",1
307
+ SH,Scott W. Hutchings,20-06,"1,181.56",2,"1,181.56",1
308
+ SH,Scott W. Hutchings,20-05,"29,202.00",1,"29,202.00",1
309
+ SH,Scott W. Hutchings,20-04,"13,282.53",4,"7,877.78",2
310
+ SH,Scott W. Hutchings,20-01,1.00,1,1.00,1
311
+ SH,Scott W. Hutchings,19-12,"1,750.29",1,"1,750.29",1
312
+ SH,Scott W. Hutchings,19-09,"25,948.94",1,0.00,0
313
+ SH,Scott W. Hutchings,19-08,"7,450.43",1,"7,450.43",1
314
+ SH,Scott W. Hutchings,19-06,"1,035.00",1,900.00,1
315
+ SH,Scott W. Hutchings,19-04,"54,401.03",2,0.00,0
316
+ SH,Scott W. Hutchings,18-09,"7,616.72",1,0.00,0
317
+ SH,Scott W. Hutchings,18-08,"1,475.00",1,"1,475.00",1
318
+ SH,Scott W. Hutchings,18-04,"36,478.33",1,"36,478.33",1
319
+ SH,Scott W. Hutchings,18-01,"1,180.00",1,0.00,1
320
+ SH,Scott W. Hutchings,17-12,"11,976.64",1,"11,976.64",1
321
+ SH,Scott W. Hutchings,17-04,"2,012.50",1,0.00,0
322
+ SH,Scott W. Hutchings,17-03,"2,945.75",1,"2,945.75",1
323
+ SH,Scott W. Hutchings,17-01,"8,466.14",1,"8,466.14",1
324
+ SH,Scott W. Hutchings,16-10,"3,307.00",2,"3,307.00",2
325
+ SH,Scott W. Hutchings,16-09,"109,065.34",9,"42,522.26",3
326
+ SH,Scott W. Hutchings,16-08,"54,917.64",3,"7,313.62",1
327
+ SH,Scott W. Hutchings,16-07,"163,636.73",10,"107,796.77",4
328
+ SH,Scott W. Hutchings,16-06,"1,632.95",1,"1,632.95",1
329
+ SH,Scott W. Hutchings,16-03,"28,555.76",4,"28,555.76",3
330
+ SH,Scott W. Hutchings,16-02,"12,310.74",2,"1,971.86",1
331
+ SH,Scott W. Hutchings,16-01,"1,837.00",3,"1,837.00",3
332
+ SH,Scott W. Hutchings,15-12,"10,976.61",2,"7,359.25",2
333
+ SH,Scott W. Hutchings,15-11,"16,621.19",2,"13,566.19",1
334
+ SH,Scott W. Hutchings,15-10,"24,387.83",6,"14,303.22",2
335
+ SH,Scott W. Hutchings,15-09,"118,664.23",5,"24,673.46",3
336
+ SH,Scott W. Hutchings,15-08,"1,048.98",1,0.00,0
337
+ SH,Scott W. Hutchings,15-07,"95,619.25",7,"14,415.78",2
338
+ SH,Scott W. Hutchings,15-06,"99,594.25",7,"49,003.67",4
339
+ SH,Scott W. Hutchings,15-05,"112,869.04",7,"29,560.71",3
340
+ SH,Scott W. Hutchings,15-04,"21,093.10",4,"10,738.88",3
341
+ SH,Scott W. Hutchings,15-03,"14,296.50",2,0.00,0
342
+ SH,Scott W. Hutchings,15-02,"11,618.59",1,"11,618.59",1
343
+ SH,Scott W. Hutchings,15-01,"6,258.54",2,"6,258.54",2
344
+ SH,Scott W. Hutchings,14-12,"22,187.84",4,"18,856.59",3
345
+ SH,Scott W. Hutchings,14-11,"32,242.82",6,"4,529.20",2
346
+ SH,Scott W. Hutchings,14-10,"2,257.50",1,"2,257.50",1
347
+ SH,Scott W. Hutchings,14-09,"11,563.38",2,"5,464.38",1
348
+ SH,Scott W. Hutchings,14-08,"38,732.79",2,"15,816.00",1
349
+ SH,Scott W. Hutchings,14-07,"224,767.31",7,0.00,0
350
+ SH,Scott W. Hutchings,14-05,"7,679.27",1,"7,679.27",1
351
+ SH,Scott W. Hutchings,14-04,"73,002.70",2,"2,531.00",1
352
+ SH,Scott W. Hutchings,14-03,"10,473.38",2,"10,473.38",2
353
+ SH,Scott W. Hutchings,14-01,"4,693.44",2,"4,693.44",2
354
+ SH,Scott W. Hutchings,13-11,"24,903.79",5,"24,903.79",5
355
+ SH,Scott W. Hutchings,13-10,"52,111.88",3,"46,274.88",2
356
+ SH,Scott W. Hutchings,13-09,"18,776.07",4,"10,416.00",2
357
+ SH,Scott W. Hutchings,13-08,"165,091.65",8,"29,680.53",4
358
+ SH,Scott W. Hutchings,13-07,"194,983.80",7,"86,501.52",4
359
+ SH,Scott W. Hutchings,13-06,"126,594.89",3,"4,023.44",2
360
+ SH,Scott W. Hutchings,13-05,"13,074.13",3,"1,269.05",1
361
+ SH,Scott W. Hutchings,13-04,"32,488.06",4,0.00,0
362
+ SH,Scott W. Hutchings,13-03,"4,346.56",1,0.00,0
363
+ SH,Scott W. Hutchings,13-02,"137,331.51",3,"130,777.50",1
364
+ SH,Scott W. Hutchings,13-01,"21,667.90",3,"18,418.90",2
365
+ SH,Scott W. Hutchings,12-12,"3,075.00",2,"3,075.00",2
366
+ SH,Scott W. Hutchings,12-10,"7,393.21",1,"7,393.21",1
367
+ SH,Scott W. Hutchings,12-09,"10,865.25",2,"10,865.25",2
368
+ SH,Scott W. Hutchings,12-08,"5,380.64",2,"5,380.64",2
369
+ SH,Scott W. Hutchings,12-07,"13,827.38",1,"13,827.38",1
370
+ SH,Scott W. Hutchings,12-06,"1,994.31",1,"1,994.31",1
371
+ SH,Scott W. Hutchings,12-05,"36,500.27",2,"32,873.00",1
372
+ SH,Scott W. Hutchings,12-04,"82,760.41",8,"61,451.75",6
373
+ SH,Scott W. Hutchings,12-03,"40,928.28",1,0.00,0
374
+ SH,Scott W. Hutchings,12-02,"31,038.80",5,"27,928.80",4
375
+ SH,Scott W. Hutchings,12-01,"216,558.25",11,"77,772.21",5
376
+ SH,Scott W. Hutchings,11-12,"250,517.08",13,"23,202.95",3
377
+ SH,Scott W. Hutchings,11-11,"294,002.43",7,"8,535.62",2
378
+ SH,Scott W. Hutchings,11-10,"212,017.00",14,"53,783.54",4
379
+ SH,Scott W. Hutchings,11-09,"511,195.51",8,"23,253.80",4
380
+ SH,Scott W. Hutchings,11-08,"1,219,894.08",29,"70,914.55",13
381
+ SH,Scott W. Hutchings,11-07,"535,737.48",8,"30,874.82",3
382
+ SH,Scott W. Hutchings,11-06,"223,309.22",20,"57,901.20",12
383
+ SH,Scott W. Hutchings,11-05,"365,253.73",22,"31,659.20",6
384
+ SH,Scott W. Hutchings,11-04,"98,058.98",10,"16,750.12",1
385
+ SH,Scott W. Hutchings,11-03,"331,806.25",20,"40,962.25",5
386
+ SH,Scott W. Hutchings,11-02,"240,994.01",13,0.00,0
387
+ SH,Scott W. Hutchings,11-01,"14,916.07",2,"2,586.00",1
388
+ SH,Scott W. Hutchings,10-11,"1,697.29",1,"1,697.29",1
389
+ SJ,Steve Jackson,21-08,"170,933.39",3,0.00,0
390
+ SW,Scott Hutchings,24-04,"43,924.00",1,0.00,0
391
+ SW,Scott Hutchings,17-02,259.65,1,259.65,1
392
+ SW,Scott Hutchings,17-01,"13,396.36",1,0.00,0
393
+ SW,Scott Hutchings,16-11,"3,294.83",1,"3,294.83",1
394
+ SW,Scott Hutchings,16-09,"4,490.05",1,"4,490.05",1
395
+ SW,Scott Hutchings,16-08,"17,074.91",1,"17,074.91",1
396
+ SW,Scott Hutchings,16-07,"6,279.11",1,"6,279.11",1
397
+ SW,Scott Hutchings,15-09,"9,820.41",1,"9,820.41",1
398
+ SW,Scott Hutchings,15-03,"3,467.49",4,"3,388.11",3
399
+ SW,Scott Hutchings,15-01,"1,360.00",1,"1,360.00",1
400
+ SW,Scott Hutchings,14-12,"7,219.00",1,"7,219.00",1
401
+ SW,Scott Hutchings,14-03,521.31,1,521.31,1
402
+ SW,Scott Hutchings,13-12,"2,148.01",1,0.00,0
403
+ SW,Scott Hutchings,13-11,"7,397.50",1,"7,397.50",1
404
+ SW,Scott Hutchings,13-08,"27,869.90",1,"27,869.90",1
405
+ SW,Scott Hutchings,13-02,"69,995.07",5,"59,219.55",3
406
+ SW,Scott Hutchings,13-01,"10,135.77",6,"1,729.43",3
407
+ SW,Scott Hutchings,12-09,"3,574.50",2,"3,574.50",2
408
+ SW,Scott Hutchings,12-06,"7,031.61",1,"7,031.61",1
409
+ SW,Scott Hutchings,12-03,"2,294.66",1,"2,294.66",1
410
+ SW,Scott Hutchings,11-12,"11,269.85",2,"3,309.85",2
411
+ SW,Scott Hutchings,11-11,"6,807.13",1,0.00,0
412
+ SW,Scott Hutchings,11-05,"29,503.80",1,0.00,0
413
+ SW,Scott Hutchings,11-03,371.74,1,0.00,0
414
+ SW,Scott Hutchings,11-02,"43,293.89",2,0.00,0
415
+ SW,Scott Hutchings,11-01,"447,765.26",20,"2,490.00",2
416
+ SW,Scott Hutchings,10-12,"25,821.16",7,"8,665.81",3
417
+ SW,Scott Hutchings,10-11,"72,284.07",9,"17,595.57",4
418
+ SW,Scott Hutchings,10-10,"403,166.43",9,0.00,1
419
+ SW,Scott Hutchings,10-09,"78,688.26",2,0.00,0
420
+ SW,Scott Hutchings,10-08,"2,033.75",1,"2,033.75",1
421
+ SW,Scott Hutchings,10-05,"150,951.76",4,0.00,0
422
+ SW,Scott Hutchings,10-04,"473,466.13",9,"2,340.00",1
423
+ ZH,Zach Hutchings,23-12,"252,818.09",5,0.00,0
424
+ ZH,Zach Hutchings,23-11,"353,308.01",4,"197,623.22",2
425
+ ZH,Zach Hutchings,23-10,"186,251.61",2,0.00,0
PM Sales Analysis by Estimator.Rproj ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Version: 1.0
2
+ ProjectId: 8a78cd92-6416-4058-b778-a84718581ebb
3
+
4
+ RestoreWorkspace: Default
5
+ SaveWorkspace: Default
6
+ AlwaysSaveHistory: Default
7
+
8
+ EnableCodeIndexing: Yes
9
+ UseSpacesForTab: Yes
10
+ NumSpacesForTab: 2
11
+ Encoding: UTF-8
12
+
13
+ RnwWeave: Sweave
14
+ LaTeX: pdfLaTeX
15
+
16
+ ProjectName: PM Sales Analysis by Estimator
app.R ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(shiny)
2
+ library(shinydashboard)
3
+ library(tidyverse)
4
+ library(lubridate)
5
+ library(plotly)
6
+ library(DBI)
7
+ library(RPostgres)
8
+ library(scales)
9
+ library(DT)
10
+ library(shinyWidgets)
11
+
12
+ # --- DATABASE CONNECTION ---
13
+ connect_db <- function() {
14
+ dbConnect(RPostgres::Postgres(),
15
+ dbname = "sales_db",
16
+ host = "localhost",
17
+ port = 5433,
18
+ user = Sys.info()[["user"]],
19
+ password = "")
20
+ }
21
+
22
+ # ... (Libraries and DB connection remain the same) ...
23
+
24
+ # --- UI ---
25
+ ui <- dashboardPage(
26
+ skin = "black",
27
+ dashboardHeader(title = span("Estimator Intelligence", style = "font-weight: bold; font-size: 18px;")),
28
+
29
+ dashboardSidebar(
30
+ width = 250,
31
+ sidebarMenu(
32
+ menuItem("Executive Dashboard", tabName = "dashboard", icon = icon("chart-area")),
33
+ menuItem("Data Management", tabName = "admin", icon = icon("database")),
34
+ hr(),
35
+
36
+ div(style = "padding: 10px;",
37
+ h5("Filter Controls", style = "color: #b8c7ce; text-transform: uppercase; font-size: 12px; margin-bottom: 10px;"),
38
+
39
+ dateRangeInput("dateRange", NULL, start = "2021-01-01", end = Sys.Date(), separator = " to "),
40
+
41
+ # --- NEW: VIEW MODE TOGGLE ---
42
+ radioGroupButtons(
43
+ inputId = "view_mode",
44
+ label = "Breakdown Mode",
45
+ choices = c("Aggregate", "Individual"),
46
+ selected = "Aggregate",
47
+ status = "success", # Green to stand out
48
+ size = "sm",
49
+ justified = TRUE
50
+ ),
51
+ br(),
52
+
53
+ radioGroupButtons(
54
+ inputId = "time_granularity",
55
+ label = "Time Scale",
56
+ choices = c("Monthly", "Quarterly"),
57
+ selected = "Monthly",
58
+ status = "primary",
59
+ size = "sm",
60
+ justified = TRUE
61
+ ),
62
+ br(),
63
+
64
+ pickerInput("estimatorSelect", "Estimators:",
65
+ choices = NULL, multiple = TRUE,
66
+ options = list(`actions-box` = TRUE, `live-search` = TRUE, `selected-text-format` = "count > 2", `count-selected-text` = "{0} Selected", `none-selected-text` = "All Company Data")),
67
+
68
+ div(style = "text-align: center; margin-top: 15px;",
69
+ actionButton("refresh", "Refresh Data", icon = icon("sync"), width = "90%", class = "btn-primary btn-sm btn-flat"))
70
+ )
71
+ )
72
+ ),
73
+
74
+ dashboardBody(
75
+ tags$head(tags$style(HTML("
76
+ .box.box-solid.box-primary>.box-header { background: #2c3e50; }
77
+ .box.box-solid.box-primary { border: 1px solid #2c3e50; }
78
+ .content-wrapper, .right-side { background-color: #f4f6f9; }
79
+ .plotly { margin-top: 10px; }
80
+ "))),
81
+
82
+ tabItems(
83
+ tabItem(tabName = "dashboard",
84
+ fluidRow(
85
+ valueBoxOutput("kpi_total_bid", width = 3),
86
+ valueBoxOutput("kpi_total_booked", width = 3),
87
+ valueBoxOutput("kpi_win_rate_amt", width = 3),
88
+ valueBoxOutput("kpi_win_rate_qty", width = 3)
89
+ ),
90
+ fluidRow(
91
+ tabBox(title = textOutput("trend_box_title"), width = 12, side = "right", selected = "Dollar Amounts ($)",
92
+ tabPanel("Dollar Amounts ($)", plotlyOutput("trend_dollars", height = "400px"), p(class = "text-muted", style = "font-size: 11px;", "In 'Individual' mode, dashed trends are removed for clarity.")),
93
+ tabPanel("Quantity (Count)", plotlyOutput("trend_qty", height = "400px")))
94
+ ),
95
+ fluidRow(
96
+ box(title = "Annual Performance", status = "primary", solidHeader = TRUE, width = 6,
97
+ plotlyOutput("annual_bar_chart", height = "400px")),
98
+
99
+ box(title = "Year-Over-Year Growth (%)", status = "primary", solidHeader = TRUE, width = 6,
100
+ fluidRow(
101
+ column(width = 7, p(class = "text-muted", style = "font-size: 11px; margin-top: 10px;", "Aggregate: Red/Green | Individual: Colored by Person")),
102
+ column(width = 5, pickerInput("yoy_metric", NULL, choices = c("Booked Revenue ($)"="amt_booked", "Bid Volume ($)"="amt_bid", "Jobs Booked (Qty)"="qty_booked", "Jobs Bid (Qty)"="qty_bid"), selected = "amt_booked", width = "100%", options = list(style = "btn-default btn-sm")))
103
+ ),
104
+ plotlyOutput("yoy_chart", height = "350px")
105
+ )
106
+ ),
107
+ fluidRow(box(title = "Top Estimator Leaderboard", status = "warning", solidHeader = TRUE, width = 12, dataTableOutput("leaderboard_table")))
108
+ ),
109
+ tabItem(tabName = "admin",
110
+ fluidRow(
111
+ box(title = "Upload Data", status = "danger", solidHeader = TRUE, width = 5,
112
+ fileInput("file1", "Upload CSV", accept = c(".csv")),
113
+ actionButton("process_upload", "Process & Import", class = "btn-danger", width = "100%")),
114
+ box(title = "System Status", status = "info", solidHeader = TRUE, width = 7,
115
+ verbatimTextOutput("db_status_text"), dataTableOutput("preview_table"))
116
+ )
117
+ )
118
+ )
119
+ )
120
+ )
121
+
122
+ # --- SERVER ---
123
+ server <- function(input, output, session) {
124
+
125
+ data_trigger <- reactiveVal(0)
126
+
127
+ get_data <- reactive({
128
+ input$refresh; data_trigger(); con <- tryCatch(connect_db(), error = function(e) return(NULL))
129
+ if(is.null(con)) return(data.frame()); if(!dbExistsTable(con, "monthly_sales")) { dbDisconnect(con); return(data.frame()) }
130
+ query <- "SELECT e.primary_name, s.*, EXTRACT(YEAR FROM s.report_date) as year_num FROM monthly_sales s JOIN estimators e ON s.estimator_id = e.id"
131
+ df <- dbGetQuery(con, query); dbDisconnect(con); return(df)
132
+ })
133
+
134
+ observeEvent(input$process_upload, {
135
+ req(input$file1); progress <- shiny::Progress$new(message = "Processing...", value = 0.2); on.exit(progress$close())
136
+ tryCatch({
137
+ raw_data <- read_csv(input$file1$datapath, show_col_types = FALSE)
138
+ clean_data <- raw_data %>% mutate(report_date = ym(MoYear)) %>% mutate(across(c(AmtBid, AmtBooked), ~ as.numeric(gsub("[\\$,]", "", .)))) %>% mutate(clean_name = case_when(Estimator == "Scott W. Hutchings" ~ "Scott Hutchings", Estimator == "SW" ~ "Scott Hutchings", Estimator == "SH" ~ "Scott Hutchings", TRUE ~ Estimator))
139
+ con <- connect_db()
140
+ unique_estimators <- unique(clean_data$clean_name)
141
+ for(name in unique_estimators){ tryCatch({ dbExecute(con, "INSERT INTO estimators (primary_name) VALUES ($1) ON CONFLICT DO NOTHING", params = list(name)) }, error = function(e) NULL) }
142
+ est_map <- dbGetQuery(con, "SELECT id, primary_name FROM estimators")
143
+ upload_ready <- clean_data %>% left_join(est_map, by = c("clean_name" = "primary_name")) %>% select(estimator_id = id, report_date, amt_bid = AmtBid, qty_bid = QtyBid, amt_booked = AmtBooked, qty_booked = QtyBooked)
144
+ dbWriteTable(con, "staging_sales", upload_ready, overwrite = TRUE, temporary = TRUE)
145
+ dbExecute(con, "INSERT INTO monthly_sales (estimator_id, report_date, amt_bid, qty_bid, amt_booked, qty_booked) SELECT estimator_id, report_date, amt_bid, qty_bid, amt_booked, qty_booked FROM staging_sales ON CONFLICT (estimator_id, report_date) DO NOTHING;")
146
+ dbExecute(con, "DROP TABLE IF EXISTS staging_sales"); dbDisconnect(con)
147
+ showNotification("Import Complete.", type = "message"); data_trigger(data_trigger() + 1)
148
+ }, error = function(e) { showNotification(paste("Error:", e$message), type = "error") })
149
+ })
150
+
151
+ observe({ df <- get_data(); if(nrow(df) > 0) { est_list <- sort(unique(df$primary_name)); updatePickerInput(session, "estimatorSelect", choices = est_list, selected = input$estimatorSelect) } })
152
+
153
+ filtered_data <- reactive({
154
+ req(input$dateRange); df <- get_data(); if(nrow(df) == 0) return(df[0, ])
155
+ df <- df %>% filter(report_date >= input$dateRange[1], report_date <= input$dateRange[2])
156
+ if (!is.null(input$estimatorSelect)) { df <- df %>% filter(primary_name %in% input$estimatorSelect) }
157
+ return(df)
158
+ })
159
+
160
+ output$trend_box_title <- renderText({ req(input$time_granularity); paste("Trends (Bid vs Booked) -", input$time_granularity, "View") })
161
+
162
+ output$kpi_total_bid <- renderValueBox({ valueBox(dollar(sum(filtered_data()$amt_bid, na.rm=T)), "Total Bid Volume", icon = icon("file-invoice-dollar"), color = "blue") })
163
+ output$kpi_total_booked <- renderValueBox({ valueBox(dollar(sum(filtered_data()$amt_booked, na.rm=T)), "Total Booked Revenue", icon = icon("money-bill-wave"), color = "green") })
164
+ output$kpi_win_rate_amt <- renderValueBox({ d <- filtered_data(); r <- sum(d$amt_booked, na.rm=T)/sum(d$amt_bid, na.rm=T); valueBox(percent(r, 0.1), "Dollar Win Rate", icon = icon("chart-line"), color = "yellow") })
165
+ output$kpi_win_rate_qty <- renderValueBox({ d <- filtered_data(); r <- sum(d$qty_booked, na.rm=T)/sum(d$qty_bid, na.rm=T); valueBox(percent(r, 0.1), "Job Win Rate", icon = icon("check-circle"), color = "purple") })
166
+
167
+ # --- LOGIC FOR TRENDS (AGGREGATE vs INDIVIDUAL) ---
168
+ render_trend_chart <- function(val_bid, val_booked, prefix) {
169
+ d <- filtered_data(); req(input$time_granularity, input$view_mode); validate(need(nrow(d) > 0, "No data."))
170
+
171
+ # 1. Prepare Data Grouping based on Mode
172
+ if(input$view_mode == "Individual") {
173
+ # Keep 'primary_name' in grouping
174
+ d_trend <- d %>%
175
+ mutate(date_group = if(input$time_granularity == "Quarterly") floor_date(report_date, "quarter") else report_date) %>%
176
+ group_by(date_group, primary_name) %>%
177
+ summarise(Bid = sum(!!sym(val_bid), na.rm=T), Booked = sum(!!sym(val_booked), na.rm=T)) %>%
178
+ pivot_longer(c(Bid, Booked), names_to = "Type", values_to = "Value")
179
+ } else {
180
+ # Aggregate everything
181
+ d_trend <- d %>%
182
+ mutate(date_group = if(input$time_granularity == "Quarterly") floor_date(report_date, "quarter") else report_date) %>%
183
+ group_by(date_group) %>%
184
+ summarise(Bid = sum(!!sym(val_bid), na.rm=T), Booked = sum(!!sym(val_booked), na.rm=T)) %>%
185
+ pivot_longer(c(Bid, Booked), names_to = "Type", values_to = "Value")
186
+ }
187
+
188
+ # 2. Base Plot
189
+ p <- ggplot(d_trend, aes(x = date_group, y = Value, color = Type, group = Type,
190
+ text = paste0("<b>Date:</b> ", format(date_group, "%m-%d-%Y"), "<br>",
191
+ "<b>Type:</b> ", Type, "<br>",
192
+ "<b>Value:</b> ", if(prefix=="$") dollar(Value, accuracy=1) else comma(Value, accuracy=1)))) +
193
+ geom_line(size = 1) +
194
+ scale_color_manual(values = c("Bid" = "#2c3e50", "Booked" = "#27ae60")) +
195
+ scale_y_continuous(labels = if(prefix=="$") dollar_format(accuracy=1) else comma_format(accuracy=1)) +
196
+ theme_minimal() + labs(x="", y="", title=NULL)
197
+
198
+ # 3. Apply Splitting Logic
199
+ if(input$view_mode == "Individual") {
200
+ # Add Faceting (Small Multiples)
201
+ p <- p + facet_wrap(~primary_name, scales = "free_y") +
202
+ theme(strip.background = element_rect(fill="#f4f6f9"), strip.text = element_text(face="bold"))
203
+ } else {
204
+ # Add Regression only in Aggregate mode
205
+ p <- p + geom_smooth(method = "lm", se = FALSE, linetype = "dashed", alpha = 0.5, size = 0.5)
206
+ }
207
+
208
+ ggplotly(p, tooltip = "text") %>% layout(legend = list(orientation = "h", x = 0.4, y = -0.2))
209
+ }
210
+
211
+ output$trend_dollars <- renderPlotly({ render_trend_chart("amt_bid", "amt_booked", "$") })
212
+ output$trend_qty <- renderPlotly({ render_trend_chart("qty_bid", "qty_booked", "") })
213
+
214
+ output$annual_bar_chart <- renderPlotly({
215
+ d <- filtered_data(); validate(need(nrow(d) > 0, "No data."));
216
+ # Logic: If Individual Mode OR (Aggregate Mode but < 6 people selected), show dodge.
217
+ # Note: Annual chart always looks better grouped by person if few are selected.
218
+ by_person <- !is.null(input$estimatorSelect) && length(input$estimatorSelect) <= 5
219
+
220
+ if (by_person) { annual <- d %>% group_by(year_num, primary_name) %>% summarise(Booked = sum(amt_booked, na.rm=T)); p <- ggplot(annual, aes(x = factor(year_num), y = Booked, fill = primary_name)) + geom_col(position = "dodge") + scale_fill_brewer(palette = "Paired")
221
+ } else { annual <- d %>% group_by(year_num) %>% summarise(Bid = sum(amt_bid, na.rm=T), Booked = sum(amt_booked, na.rm=T)) %>% pivot_longer(c(Bid, Booked), names_to = "Type", values_to = "Value"); p <- ggplot(annual, aes(x = factor(year_num), y = Value, fill = Type)) + geom_col(position = "dodge") + scale_fill_manual(values = c("Bid" = "#95a5a6", "Booked" = "#27ae60")) }
222
+ ggplotly(p + scale_y_continuous(labels = dollar_format()) + labs(x="",y="",fill="") + theme_minimal())
223
+ })
224
+
225
+ # --- LOGIC FOR YOY (AGGREGATE vs INDIVIDUAL) ---
226
+ output$yoy_chart <- renderPlotly({
227
+ d <- filtered_data(); req(input$yoy_metric, input$view_mode); validate(need(nrow(d) > 0, "No data.")); metric_sym <- sym(input$yoy_metric)
228
+
229
+ if(input$view_mode == "Individual") {
230
+ # Individual Mode: Colored by Person, Side-by-Side bars
231
+ validate(need(length(unique(d$primary_name)) <= 10, "For Individual YoY View, please select 10 or fewer estimators."))
232
+
233
+ annual_growth <- d %>% group_by(year_num, primary_name) %>% summarise(Total_Value = sum(!!metric_sym, na.rm=T)) %>% arrange(year_num) %>% group_by(primary_name) %>% mutate(Growth_Pct = (Total_Value - lag(Total_Value)) / lag(Total_Value)) %>% filter(!is.na(Growth_Pct))
234
+
235
+ p <- ggplot(annual_growth, aes(x = factor(year_num), y = Growth_Pct, fill = primary_name,
236
+ text = paste("Year:", year_num, "<br>Estimator:", primary_name, "<br>Growth:", percent(Growth_Pct, 0.1)))) +
237
+ geom_col(position = "dodge") +
238
+ scale_fill_brewer(palette = "Paired")
239
+
240
+ } else {
241
+ # Aggregate Mode: Red/Green Bars
242
+ annual_growth <- d %>% group_by(year_num) %>% summarise(Total_Value = sum(!!metric_sym, na.rm=T)) %>% arrange(year_num) %>% mutate(Growth_Pct = (Total_Value - lag(Total_Value)) / lag(Total_Value)) %>% filter(!is.na(Growth_Pct))
243
+
244
+ p <- ggplot(annual_growth, aes(x = factor(year_num), y = Growth_Pct, fill = Growth_Pct > 0,
245
+ text = paste("Year:", year_num, "<br>Growth:", percent(Growth_Pct, 0.1)))) +
246
+ geom_col(show.legend = FALSE) +
247
+ scale_fill_manual(values = c("TRUE" = "#27ae60", "FALSE" = "#c0392b"))
248
+ }
249
+
250
+ p <- p + geom_hline(yintercept = 0, color = "black") + scale_y_continuous(labels = percent_format()) + labs(x = "Year", y = "Growth %") + theme_minimal()
251
+ ggplotly(p, tooltip = "text")
252
+ })
253
+
254
+ output$leaderboard_table <- renderDataTable({
255
+ d <- filtered_data(); if(nrow(d) == 0) return(NULL)
256
+ leaderboard <- d %>% group_by(primary_name) %>% summarise(Bids = sum(amt_bid, na.rm = TRUE), Booked = sum(amt_booked, na.rm = TRUE), Win_Rate = sum(amt_booked, na.rm = TRUE) / sum(amt_bid, na.rm = TRUE), Jobs_Won = sum(qty_booked, na.rm = TRUE), Avg_Bid_Size = mean(amt_bid, na.rm = TRUE)) %>% arrange(desc(Booked)) %>% mutate(Bids = dollar(Bids, accuracy = 1), Booked = dollar(Booked, accuracy = 1), Win_Rate = percent(Win_Rate, accuracy = 0.1), Avg_Bid_Size = dollar(Avg_Bid_Size, accuracy = 1)) %>% rename(Estimator = primary_name, `Total Revenue` = Booked, `Total Bids` = Bids, `Win %` = Win_Rate, `Jobs` = Jobs_Won, `Avg Job Size` = Avg_Bid_Size)
257
+ datatable(leaderboard, options = list(dom = 't', pageLength = 10, scrollX = TRUE))
258
+ })
259
+
260
+ output$db_status_text <- renderText({ d <- get_data(); paste("Database records loaded:", comma(nrow(d))) })
261
+ output$preview_table <- renderDataTable({ d <- get_data(); if(nrow(d)==0) return(NULL); d %>% arrange(desc(report_date)) %>% head(5) %>% select(Estimator=primary_name, Date=report_date, Bid=amt_bid, Booked=amt_booked) }, options = list(dom='t', searching=FALSE))
262
+ }
263
+
264
+ shinyApp(ui, server)
database.sql ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -- 1. Create a table for Estimators (handling name variations)
2
+ CREATE TABLE estimators (
3
+ id SERIAL PRIMARY KEY,
4
+ primary_name VARCHAR(100) UNIQUE NOT NULL, -- The "Clean" name (e.g., "Scott Hutchings")
5
+ active BOOLEAN DEFAULT TRUE
6
+ );
7
+
8
+ -- 2. Create the Sales Data table
9
+ CREATE TABLE monthly_sales (x
10
+ id SERIAL PRIMARY KEY,
11
+ estimator_id INTEGER REFERENCES estimators(id),
12
+ report_date DATE NOT NULL, -- Converted from "19-06" to "2019-06-01"
13
+ amt_bid NUMERIC(15, 2),
14
+ qty_bid INTEGER,
15
+ amt_booked NUMERIC(15, 2),
16
+ qty_booked INTEGER,
17
+ UNIQUE(estimator_id, report_date) -- Prevents uploading the same month twice
18
+ );
etl_process.R ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(tidyverse)
2
+ library(lubridate)
3
+ library(DBI)
4
+ library(RPostgres)
5
+
6
+ # 1. Connect to DB
7
+ con <- dbConnect(RPostgres::Postgres(), dbname = "sales_db",
8
+ host = "localhost", port = 5433,
9
+ user = Sys.info()[["user"]], password = "")
10
+
11
+ # 2. Read and Clean CSV
12
+ raw_data <- read_csv("Bid_SalesAnalysisByEstimatorByMonth_121125.csv", show_col_types = FALSE)
13
+
14
+ clean_data <- raw_data %>%
15
+ mutate(report_date = ym(MoYear)) %>%
16
+ mutate(across(c(AmtBid, AmtBooked), ~ as.numeric(gsub("[\\$,]", "", .)))) %>%
17
+ mutate(clean_name = case_when(
18
+ Estimator == "Scott W. Hutchings" ~ "Scott Hutchings",
19
+ Estimator == "SW" ~ "Scott Hutchings",
20
+ Estimator == "SH" ~ "Scott Hutchings",
21
+ TRUE ~ Estimator
22
+ ))
23
+
24
+ # 3. Update Estimators Table
25
+ unique_estimators <- unique(clean_data$clean_name)
26
+
27
+ for(name in unique_estimators){
28
+ # Check if exists, if not, insert
29
+ exists <- dbGetQuery(con, "SELECT id FROM estimators WHERE primary_name = $1", params = list(name))
30
+ if(nrow(exists) == 0){
31
+ dbExecute(con, "INSERT INTO estimators (primary_name) VALUES ($1)", params = list(name))
32
+ }
33
+ }
34
+
35
+ # 4. Upload Sales Data
36
+ est_map <- dbGetQuery(con, "SELECT id, primary_name FROM estimators")
37
+
38
+ upload_ready <- clean_data %>%
39
+ left_join(est_map, by = c("clean_name" = "primary_name")) %>%
40
+ select(estimator_id = id, report_date, amt_bid = AmtBid, qty_bid = QtyBid,
41
+ amt_booked = AmtBooked, qty_booked = QtyBooked)
42
+
43
+ # Write to DB (Append mode)
44
+ tryCatch({
45
+ dbWriteTable(con, "monthly_sales", upload_ready, append = TRUE, row.names = FALSE)
46
+ print("Data Successfully Uploaded to Port 5433!")
47
+ }, error = function(e) {
48
+ print("Data likely already exists. (Duplicate key error expected if running twice).")
49
+ })
50
+
51
+ dbDisconnect(con)
force_load.R ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(DBI)
2
+ library(RPostgres)
3
+ library(tidyverse)
4
+ library(lubridate)
5
+ library(readr)
6
+
7
+ # --- 1. SETTINGS ---
8
+ CSV_FILENAME <- "Bid_SalesAnalysisByEstimatorByMonth_121125.csv"
9
+ DB_PORT <- 5433
10
+
11
+ print("--- DIAGNOSTIC START ---")
12
+
13
+ # --- 2. CHECK FILE EXISTENCE ---
14
+ # This checks if RStudio is looking in the right folder
15
+ if (file.exists(CSV_FILENAME)) {
16
+ print(paste("✅ SUCCESS: Found file:", CSV_FILENAME))
17
+ } else {
18
+ print(paste("❌ ERROR: Could not find file:", CSV_FILENAME))
19
+ print(paste(" R is currently looking in:", getwd()))
20
+ stop("Stoppping script. Please move the CSV to the folder listed above.")
21
+ }
22
+
23
+ # --- 3. CONNECT TO DATABASE ---
24
+ tryCatch({
25
+ con <- dbConnect(RPostgres::Postgres(),
26
+ dbname = "sales_db",
27
+ host = "localhost",
28
+ port = DB_PORT,
29
+ user = Sys.info()[["user"]],
30
+ password = "")
31
+ print("✅ SUCCESS: Connected to Database.")
32
+ }, error = function(e) {
33
+ print("❌ ERROR: Could not connect to Database. Make sure Postgres.app is running.")
34
+ stop(e)
35
+ })
36
+
37
+ # --- 4. LOAD DATA ---
38
+ print("--- Attempting Data Load ---")
39
+
40
+ raw_data <- read_csv(CSV_FILENAME, show_col_types = FALSE)
41
+
42
+ clean_data <- raw_data %>%
43
+ mutate(report_date = ym(MoYear)) %>%
44
+ mutate(across(c(AmtBid, AmtBooked), ~ as.numeric(gsub("[\\$,]", "", .)))) %>%
45
+ mutate(clean_name = case_when(
46
+ Estimator == "Scott W. Hutchings" ~ "Scott Hutchings",
47
+ Estimator == "SW" ~ "Scott Hutchings",
48
+ Estimator == "SH" ~ "Scott Hutchings",
49
+ TRUE ~ Estimator
50
+ ))
51
+
52
+ # Insert Estimator Names
53
+ unique_estimators <- unique(clean_data$clean_name)
54
+ count_new_names <- 0
55
+
56
+ for(name in unique_estimators){
57
+ exists <- dbGetQuery(con, "SELECT id FROM estimators WHERE primary_name = $1", params = list(name))
58
+ if(nrow(exists) == 0){
59
+ dbExecute(con, "INSERT INTO estimators (primary_name) VALUES ($1)", params = list(name))
60
+ count_new_names <- count_new_names + 1
61
+ }
62
+ }
63
+ print(paste(" Processed Estimators. Added", count_new_names, "new names."))
64
+
65
+ # Insert Sales Data
66
+ est_map <- dbGetQuery(con, "SELECT id, primary_name FROM estimators")
67
+
68
+ upload_ready <- clean_data %>%
69
+ left_join(est_map, by = c("clean_name" = "primary_name")) %>%
70
+ select(estimator_id = id, report_date, amt_bid = AmtBid, qty_bid = QtyBid,
71
+ amt_booked = AmtBooked, qty_booked = QtyBooked)
72
+
73
+ # Write to DB
74
+ tryCatch({
75
+ dbWriteTable(con, "monthly_sales", upload_ready, append = TRUE, row.names = FALSE)
76
+ print(paste("✅ SUCCESS: Uploaded", nrow(upload_ready), "sales records."))
77
+ }, error = function(e) {
78
+ print("⚠️ NOTE: Data write skipped (likely duplicate data).")
79
+ })
80
+
81
+ # --- 5. FINAL VERIFICATION ---
82
+ row_count <- dbGetQuery(con, "SELECT count(*) FROM monthly_sales")
83
+ print(paste("--- FINAL DATABASE STATUS: The table now has", row_count, "rows. ---"))
84
+
85
+ dbDisconnect(con)
fore_load.R ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(DBI)
2
+ library(RPostgres)
3
+ library(tidyverse)
4
+ library(lubridate)
5
+ library(readr)
6
+
7
+ # --- 1. SETTINGS ---
8
+ CSV_FILENAME <- "Bid_SalesAnalysisByEstimatorByMonth_121125.csv"
9
+ DB_PORT <- 5433
10
+
11
+ print("--- DIAGNOSTIC START ---")
12
+
13
+ # --- 2. CHECK FILE EXISTENCE ---
14
+ # This checks if RStudio is looking in the right folder
15
+ if (file.exists(CSV_FILENAME)) {
16
+ print(paste("✅ SUCCESS: Found file:", CSV_FILENAME))
17
+ } else {
18
+ print(paste("❌ ERROR: Could not find file:", CSV_FILENAME))
19
+ print(paste(" R is currently looking in:", getwd()))
20
+ stop("Stoppping script. Please move the CSV to the folder listed above.")
21
+ }
22
+
23
+ # --- 3. CONNECT TO DATABASE ---
24
+ tryCatch({
25
+ con <- dbConnect(RPostgres::Postgres(),
26
+ dbname = "sales_db",
27
+ host = "localhost",
28
+ port = DB_PORT,
29
+ user = Sys.info()[["user"]],
30
+ password = "")
31
+ print("✅ SUCCESS: Connected to Database.")
32
+ }, error = function(e) {
33
+ print("❌ ERROR: Could not connect to Database. Make sure Postgres.app is running.")
34
+ stop(e)
35
+ })
36
+
37
+ # --- 4. LOAD DATA ---
38
+ print("--- Attempting Data Load ---")
39
+
40
+ raw_data <- read_csv(CSV_FILENAME, show_col_types = FALSE)
41
+
42
+ clean_data <- raw_data %>%
43
+ mutate(report_date = ym(MoYear)) %>%
44
+ mutate(across(c(AmtBid, AmtBooked), ~ as.numeric(gsub("[\\$,]", "", .)))) %>%
45
+ mutate(clean_name = case_when(
46
+ Estimator == "Scott W. Hutchings" ~ "Scott Hutchings",
47
+ Estimator == "SW" ~ "Scott Hutchings",
48
+ Estimator == "SH" ~ "Scott Hutchings",
49
+ TRUE ~ Estimator
50
+ ))
51
+
52
+ # Insert Estimator Names
53
+ unique_estimators <- unique(clean_data$clean_name)
54
+ count_new_names <- 0
55
+
56
+ for(name in unique_estimators){
57
+ exists <- dbGetQuery(con, "SELECT id FROM estimators WHERE primary_name = $1", params = list(name))
58
+ if(nrow(exists) == 0){
59
+ dbExecute(con, "INSERT INTO estimators (primary_name) VALUES ($1)", params = list(name))
60
+ count_new_names <- count_new_names + 1
61
+ }
62
+ }
63
+ print(paste(" Processed Estimators. Added", count_new_names, "new names."))
64
+
65
+ # Insert Sales Data
66
+ est_map <- dbGetQuery(con, "SELECT id, primary_name FROM estimators")
67
+
68
+ upload_ready <- clean_data %>%
69
+ left_join(est_map, by = c("clean_name" = "primary_name")) %>%
70
+ select(estimator_id = id, report_date, amt_bid = AmtBid, qty_bid = QtyBid,
71
+ amt_booked = AmtBooked, qty_booked = QtyBooked)
72
+
73
+ # Write to DB
74
+ tryCatch({
75
+ dbWriteTable(con, "monthly_sales", upload_ready, append = TRUE, row.names = FALSE)
76
+ print(paste("✅ SUCCESS: Uploaded", nrow(upload_ready), "sales records."))
77
+ }, error = function(e) {
78
+ print("⚠️ NOTE: Data write skipped (likely duplicate data).")
79
+ })
80
+
81
+ # --- 5. FINAL VERIFICATION ---
82
+ row_count <- dbGetQuery(con, "SELECT count(*) FROM monthly_sales")
83
+ print(paste("--- FINAL DATABASE STATUS: The table now has", row_count, "rows. ---"))
84
+
85
+ dbDisconnect(con)
86
+
sales_db.R ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(DBI)
2
+ library(RPostgres)
3
+
4
+ # 1. Connect to the system database to create your App DB
5
+ # Note: We use Sys.info()[["user"]] to get your Mac username automatically
6
+ sys_con <- dbConnect(RPostgres::Postgres(),
7
+ dbname = "postgres",
8
+ host = "localhost",
9
+ port = 5433, # <--- Your new port
10
+ user = Sys.info()[["user"]],
11
+ password = "")
12
+
13
+ # 2. Create the 'sales_db' database
14
+ tryCatch({
15
+ dbExecute(sys_con, "CREATE DATABASE sales_db;")
16
+ print("Database 'sales_db' created successfully.")
17
+ }, error = function(e) {
18
+ print("Database 'sales_db' likely already exists. Continuing...")
19
+ })
20
+
21
+ dbDisconnect(sys_con)
22
+
23
+ # 3. Connect to the new 'sales_db' to build tables
24
+ con <- dbConnect(RPostgres::Postgres(),
25
+ dbname = "sales_db",
26
+ host = "localhost",
27
+ port = 5433,
28
+ user = Sys.info()[["user"]],
29
+ password = "")
30
+
31
+ # 4. Create Tables (Embedded SQL to ensure it works)
32
+ # Create Estimators Table
33
+ dbExecute(con, "
34
+ CREATE TABLE IF NOT EXISTS estimators (
35
+ id SERIAL PRIMARY KEY,
36
+ primary_name VARCHAR(100) UNIQUE NOT NULL,
37
+ active BOOLEAN DEFAULT TRUE
38
+ );
39
+ ")
40
+
41
+ # Create Sales Data Table
42
+ dbExecute(con, "
43
+ CREATE TABLE IF NOT EXISTS monthly_sales (
44
+ id SERIAL PRIMARY KEY,
45
+ estimator_id INTEGER REFERENCES estimators(id),
46
+ report_date DATE NOT NULL,
47
+ amt_bid NUMERIC(15, 2),
48
+ qty_bid INTEGER,
49
+ amt_booked NUMERIC(15, 2),
50
+ qty_booked INTEGER,
51
+ UNIQUE(estimator_id, report_date)
52
+ );
53
+ ")
54
+
55
+ print("Tables created successfully on Port 5433!")
56
+ dbDisconnect(con)
setup_database.R ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(DBI)
2
+ library(RPostgres)
3
+ library(tidyverse)
4
+ library(lubridate)
5
+ library(readr)
6
+
7
+ # --- CONFIGURATION ---
8
+ DB_PORT <- 5433 # The port you selected
9
+ MAC_USER <- Sys.info()[["user"]] # Automatically gets your Mac username
10
+ CSV_FILE <- "Bid_SalesAnalysisByEstimatorByMonth_121125.csv"
11
+
12
+ # --- STEP 1: CREATE THE DATABASE ---
13
+ print("--- Step 1: Creating Database... ---")
14
+
15
+ # We must connect to the default 'postgres' database first to create a new one
16
+ con_sys <- dbConnect(RPostgres::Postgres(),
17
+ dbname = "postgres",
18
+ host = "localhost",
19
+ port = DB_PORT,
20
+ user = MAC_USER,
21
+ password = "")
22
+
23
+ # Try to create the database (fails gracefully if it already exists)
24
+ tryCatch({
25
+ dbExecute(con_sys, "CREATE DATABASE sales_db")
26
+ print("SUCCESS: Database 'sales_db' created.")
27
+ }, error = function(e) {
28
+ print("NOTE: Database 'sales_db' already exists. Moving on...")
29
+ })
30
+
31
+ dbDisconnect(con_sys)
32
+
33
+ # --- STEP 2: CREATE TABLES ---
34
+ print("--- Step 2: Creating Tables... ---")
35
+
36
+ # Now connect to the actual 'sales_db'
37
+ con <- dbConnect(RPostgres::Postgres(),
38
+ dbname = "sales_db",
39
+ host = "localhost",
40
+ port = DB_PORT,
41
+ user = MAC_USER,
42
+ password = "")
43
+
44
+ # Create 'estimators' table
45
+ dbExecute(con, "
46
+ CREATE TABLE IF NOT EXISTS estimators (
47
+ id SERIAL PRIMARY KEY,
48
+ primary_name VARCHAR(100) UNIQUE NOT NULL,
49
+ active BOOLEAN DEFAULT TRUE
50
+ );
51
+ ")
52
+
53
+ # Create 'monthly_sales' table
54
+ dbExecute(con, "
55
+ CREATE TABLE IF NOT EXISTS monthly_sales (
56
+ id SERIAL PRIMARY KEY,
57
+ estimator_id INTEGER REFERENCES estimators(id),
58
+ report_date DATE NOT NULL,
59
+ amt_bid NUMERIC(15, 2),
60
+ qty_bid INTEGER,
61
+ amt_booked NUMERIC(15, 2),
62
+ qty_booked INTEGER,
63
+ UNIQUE(estimator_id, report_date)
64
+ );
65
+ ")
66
+ print("SUCCESS: Tables created.")
67
+
68
+ # --- STEP 3: LOAD CSV DATA ---
69
+ print("--- Step 3: Loading Data... ---")
70
+
71
+ if (file.exists(CSV_FILE)) {
72
+ # Read and Clean Data
73
+ raw_data <- read_csv(CSV_FILE, show_col_types = FALSE)
74
+
75
+ clean_data <- raw_data %>%
76
+ mutate(report_date = ym(MoYear)) %>%
77
+ mutate(across(c(AmtBid, AmtBooked), ~ as.numeric(gsub("[\\$,]", "", .)))) %>%
78
+ mutate(clean_name = case_when(
79
+ Estimator == "Scott W. Hutchings" ~ "Scott Hutchings",
80
+ Estimator == "SW" ~ "Scott Hutchings",
81
+ Estimator == "SH" ~ "Scott Hutchings",
82
+ TRUE ~ Estimator
83
+ ))
84
+
85
+ # Update Estimators Table (Insert new names)
86
+ unique_estimators <- unique(clean_data$clean_name)
87
+ for(name in unique_estimators){
88
+ exists <- dbGetQuery(con, "SELECT id FROM estimators WHERE primary_name = $1", params = list(name))
89
+ if(nrow(exists) == 0){
90
+ dbExecute(con, "INSERT INTO estimators (primary_name) VALUES ($1)", params = list(name))
91
+ }
92
+ }
93
+
94
+ # Prepare Sales Data for Upload
95
+ est_map <- dbGetQuery(con, "SELECT id, primary_name FROM estimators")
96
+
97
+ upload_ready <- clean_data %>%
98
+ left_join(est_map, by = c("clean_name" = "primary_name")) %>%
99
+ select(estimator_id = id, report_date, amt_bid = AmtBid, qty_bid = QtyBid,
100
+ amt_booked = AmtBooked, qty_booked = QtyBooked)
101
+
102
+ # Write to DB
103
+ tryCatch({
104
+ # We use 'on conflict do nothing' logic via a safe append approach
105
+ # Since RPostgres dbWriteTable is simple, we just try/catch duplicates
106
+ dbWriteTable(con, "monthly_sales", upload_ready, append = TRUE, row.names = FALSE)
107
+ print("SUCCESS: Data uploaded to database.")
108
+ }, error = function(e) {
109
+ print("NOTE: Data might already exist. (Ignoring duplicate errors)")
110
+ })
111
+
112
+ } else {
113
+ print("ERROR: CSV file not found. Make sure the file name is correct.")
114
+ }
115
+
116
+ dbDisconnect(con)
117
+ print("--- SETUP COMPLETE ---")
setup_database.sql ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(DBI)
2
+ library(RPostgres)
3
+ library(readr) # To read your .sql file
4
+
5
+ # 1. Connect to the 'default' postgres database to create your specific App DB
6
+ # (You usually can't create a database while connected to it, so we connect to 'postgres' first)
7
+ sys_con <- dbConnect(RPostgres::Postgres(),
8
+ dbname = "postgres", # Default system DB
9
+ host = "localhost",
10
+ user = "postgres",
11
+ password = "your_password_here") # <--- UPDATE THIS
12
+
13
+ # 2. Create the new database (if it doesn't exist)
14
+ # We wrap in tryCatch because if it exists, it throws an error.
15
+ tryCatch({
16
+ dbExecute(sys_con, "CREATE DATABASE sales_db;")
17
+ print("Database 'sales_db' created successfully.")
18
+ }, error = function(e) {
19
+ print("Database 'sales_db' already exists or could not be created.")
20
+ })
21
+
22
+ dbDisconnect(sys_con) # Disconnect from system DB
23
+
24
+ # 3. Connect to YOUR new 'sales_db'
25
+ con <- dbConnect(RPostgres::Postgres(),
26
+ dbname = "sales_db",
27
+ host = "localhost",
28
+ user = "postgres",
29
+ password = "ggdata2014") # <--- UPDATE THIS
30
+
31
+ # 4. Read your SQL file and execute it
32
+ # This assumes 'database.sql' is in your R Project root folder
33
+ sql_commands <- read_file("database.sql")
34
+
35
+ # RPostgres sometimes struggles with multiple SQL commands in one string.
36
+ # We split them by the semicolon to run them one by one.
37
+ statements <- unlist(strsplit(sql_commands, ";"))
38
+
39
+ # Execute each statement
40
+ for (stmt in statements) {
41
+ # clean up whitespace
42
+ stmt_clean <- trimws(stmt)
43
+ if (nchar(stmt_clean) > 0) {
44
+ tryCatch({
45
+ dbExecute(con, stmt_clean)
46
+ print(paste("Executed:", substr(stmt_clean, 1, 50), "..."))
47
+ }, error = function(e) {
48
+ print(paste("Error executing:", substr(stmt_clean, 1, 50)))
49
+ print(e)
50
+ })
51
+ }
52
+ }
53
+
54
+ print("Tables created successfully!")
55
+ dbDisconnect(con)