-
Notifications
You must be signed in to change notification settings - Fork 8
/
MasterMerchant.lua
3342 lines (2971 loc) · 137 KB
/
MasterMerchant.lua
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- MasterMerchant Main Addon File
-- Last Updated September 15, 2014
-- Written July 2014 by Dan Stone (@khaibit) - [email protected]
-- Extended Feb 2015 - Oct 2016 by (@Philgo68) - [email protected]
-- Released under terms in license accompanying this file.
-- Distribution without license is prohibited!
local LMP = LibMediaProvider
local internal = _G["LibGuildStore_Internal"]
local sales_data = _G["LibGuildStore_SalesData"]
local sr_index = _G["LibGuildStore_SalesIndex"]
local listings_data = _G["LibGuildStore_ListingsData"]
local purchases_data = _G["LibGuildStore_PurchaseData"]
local mmUtils = _G["MasterMerchant_Internal"]
local OriginalSetupPendingPost
--[[ can not use MasterMerchant.itemsViewSize for example
because that will not be available this early.
]]--
local ITEMS = 'items_vs'
local GUILDS = 'guild_vs'
local LISTINGS = 'listings_vs'
local PURCHASES = 'purchases_vs'
local REPORTS = 'reports_vs'
------------------------------
--- MM Stuff ---
------------------------------
function MasterMerchant.CenterScreenAnnounce_AddMessage(eventId, category, ...)
local messageParams = CENTER_SCREEN_ANNOUNCE:CreateMessageParams(category)
messageParams:ConvertOldParams(...)
messageParams:SetLifespanMS(3500)
CENTER_SCREEN_ANNOUNCE:AddMessageWithParams(messageParams)
end
function MasterMerchant:SetupColorDefs()
MasterMerchant:dm("Debug", "SetupColorDefs")
local guildChatCategories = {}
guildChatCategories[1] = CHAT_CATEGORY_GUILD_1
guildChatCategories[2] = CHAT_CATEGORY_GUILD_2
guildChatCategories[3] = CHAT_CATEGORY_GUILD_3
guildChatCategories[4] = CHAT_CATEGORY_GUILD_4
guildChatCategories[5] = CHAT_CATEGORY_GUILD_5
for index = 1, GetNumGuilds() do
local guildId = GetGuildId(index)
local guildName = GetGuildName(guildId)
self.guildColorDefs[guildName] = ZO_ColorDef:New("FFFFFFFF")
self.guildColorDefs[guildName]:SetRGB(GetChatCategoryColor(guildChatCategories[index]))
end
for index = MM_DEAL_VALUE_OKAY, MM_DEAL_VALUE_BUYIT do
self.dealValueColorDefs[index] = ZO_ColorDef.FromInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, index)
end
self.dealValueColorDefs[MM_DEAL_VALUE_OVERPRICED] = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.98, 0.01, 0.01, 1))
MM_COLOR_BONANZA_BLUE = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.21, 0.54, 0.94, 1))
MM_COLOR_RED_NORMAL = self.dealValueColorDefs[MM_DEAL_VALUE_OVERPRICED]
MM_COLOR_YELLOW_NORMAL = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.84, 0.71, 0.15, 1))
MM_COLOR_YELLOW_SELECTED = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.84, 0.81, 0.15, 1))
MM_COLOR_YELLOW_MOUSEOVER = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(1, 0.996, 0, 1))
MM_COLOR_GREEN_NORMAL = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.18, 0.77, 0.05, 1))
MM_COLOR_GREEN_MOUSEOVER = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.32, 0.90, 0.18, 1))
MM_COLOR_BLUE_NORMAL = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.21, 0.54, 0.94, 1))
MM_COLOR_BLUE_MOUSEOVER = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.34, 0.67, 1, 1))
MM_TEXT_COLOR_NORMAL = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.77254901960784, 0.76078431372549, 0.61960784313725, 1))
MM_TEXT_COLOR_MOUSEOVER = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.93725490196078, 0.92156862745098, 0.74509803921569, 1))
MM_TEXT_COLOR_PINK = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(1, 0.047058823529412, 0.67843137254902, 1))
MM_TEXT_COLOR_ORANGE = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(1, 0.38039215686275, 0.12156862745098, 1))
MM_TEXT_COLOR_GREY = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(0.30196078431373, 0.30196078431373, 0.30196078431373, 1))
MM_TEXT_COLOR_WHITE = ZO_ColorDef:New(ZO_ColorDef.FloatsToHex(1, 1, 1, 1))
end
function MasterMerchant:CheckTimeframe()
-- setup focus info
local daysRange = MM_DAYS_RANGE_ALL
local dayCutoff = GetTimeStamp()
if not MasterMerchant.isInitialized then
return dayCutoff - (daysRange * ZO_ONE_DAY_IN_SECONDS), daysRange
end
local range = MasterMerchant.systemSavedVariables.defaultDays
dayCutoff = MasterMerchant.dateRanges[MM_DATERANGE_TODAY].startTimestamp
if IsControlKeyDown() and IsShiftKeyDown() then
range = MasterMerchant.systemSavedVariables.ctrlShiftDays
elseif IsControlKeyDown() then
range = MasterMerchant.systemSavedVariables.ctrlDays
elseif IsShiftKeyDown() then
range = MasterMerchant.systemSavedVariables.shiftDays
end
-- 10000 for numDays is more or less like saying it is undefined
if range == MM_RANGE_VALUE_NONE then return MM_DAYS_RANGE_NONE, MM_DAYS_RANGE_NONE end
if range == MM_RANGE_VALUE_ALL then daysRange = MM_DAYS_RANGE_ALL end
if range == MM_RANGE_VALUE_FOCUS1 then daysRange = MasterMerchant.systemSavedVariables.focus1 end
if range == MM_RANGE_VALUE_FOCUS2 then daysRange = MasterMerchant.systemSavedVariables.focus2 end
if range == MM_RANGE_VALUE_FOCUS3 then daysRange = MasterMerchant.systemSavedVariables.focus3 end
return dayCutoff - (daysRange * ZO_ONE_DAY_IN_SECONDS), daysRange
end
function MasterMerchant:IsInBlackList(str)
if MasterMerchant.systemSavedVariables.blacklist == MM_STRING_EMPTY then return false end
return zo_plainstrfind(MasterMerchant.systemSavedVariables.blacklist, str)
end
local function RemoveListingsPerBlacklist(list)
local nameInBlacklist = nil
local currentGuild = nil
local currentSeller = nil
local dataList = { }
local statsData = { }
local function IsNameInBlacklist()
local blacklistTable = MasterMerchant.blacklistTable
if blacklistTable == nil then return false end
return (currentGuild and blacklistTable[currentGuild]) or
(currentSeller and blacklistTable[currentSeller])
end
for _, item in pairs(list) do
currentGuild = internal:GetGuildNameByIndex(item.guild)
currentSeller = internal:GetAccountNameByIndex(item.seller)
nameInBlacklist = IsNameInBlacklist()
if not nameInBlacklist then
local individualSale = item.price / item.quant
dataList[#dataList + 1] = item
statsData[#statsData + 1] = individualSale
end
end
return dataList, statsData
end
local stats = {}
-- Get the mean value of a table
function stats.mean(t)
local sum = 0
local count = 0
for _, individualSale in pairs(t) do
sum = sum + individualSale
count = count + 1
end
return (sum / count), count, sum
end
-- Get the mode of a table. Returns a table of values.
-- Works on anything (not just numbers).
function stats.mode(t)
local counts = {}
for _, individualSale in pairs(t) do
if counts[individualSale] == nil then
counts[individualSale] = 1
else
counts[individualSale] = counts[individualSale] + 1
end
end
local biggestCount = 0
for _, v in pairs(counts) do
if v > biggestCount then
biggestCount = v
end
end
local modeValues = {}
for k, v in pairs(counts) do
if v == biggestCount then
table.insert(modeValues, k)
end
end
return modeValues
end
--[[ Get the median of a table.
Modified: Requires the table to be sorted already
]]--
--(190 –z = (x – μ) / σ 150) / 25 = 1.6.
function stats.median(t, index, range)
local temp = {}
local hasRange = index ~= nil and range ~= nil
if hasRange then
for i = index, range do
local individualSale = t[i]
temp[#temp + 1] = individualSale
end
else
temp = t
end
table.sort(temp)
-- If we have an even number of table elements or odd.
if math.fmod(#temp, 2) == 0 then
-- Return mean value of middle two elements
local middleIndex = zo_ceil(#temp / 2)
return (temp[middleIndex] + temp[middleIndex + 1]) / 2
else
-- Return middle element
local middleIndex = zo_ceil(#temp / 2)
return temp[middleIndex]
end
end
-- /script d({MasterMerchant.stats.mean(MasterMerchant.a_test)})
function stats.standardDeviation(t)
local mean
local vm
local sum = 0
local count = 0
local result
mean = stats.mean(t)
for _, individualSale in pairs(t) do
if type(individualSale) == 'number' then
vm = individualSale - mean
sum = sum + (vm * vm)
count = count + 1
end
end
if count <= 1 then
return 0
end
result = math.sqrt(sum / (count - 1))
return result
end
function stats.zscore(individualSale, mean, standardDeviation)
local result = (individualSale - mean) / standardDeviation
if result ~= result then return 0 end
return result
end
function stats.findMinMax(t)
local maxVal = -math.huge
local minVal = math.huge
for _, individualSale in pairs(t) do
maxVal = zo_max(maxVal, individualSale)
minVal = zo_min(minVal, individualSale)
end
return maxVal, minVal
end
function stats.range(t)
local highest, lowest = stats.findMinMax(t)
return highest - lowest
end
function stats.getMiddleIndex(count)
local evenNumber = false
local quotient, remainder = math.modf(count / 2)
if remainder == 0 then evenNumber = true end
local middleIndex = quotient + zo_floor(0.5 + remainder)
return middleIndex, evenNumber
end
function stats.medianAbsoluteDeviation(t)
local medianValue = stats.median(t)
local absoluteDeviations = {}
for _, value in pairs(t) do
local absoluteDeviation = zo_abs(value - medianValue)
table.insert(absoluteDeviations, absoluteDeviation)
end
return stats.median(absoluteDeviations)
end
function stats.calculateMADThreshold(statsData, maxDev)
local medianAbsoluteDev = stats.medianAbsoluteDeviation(statsData)
local median = stats.median(statsData)
local madThreshold = median + (medianAbsoluteDev * maxDev)
return madThreshold
end
--[[ we do not use this function in there are less then three
items in the table.
middleIndex will be rounded up when odd
]]--
function stats.interquartileRange(statsData)
local statsDataCount = #statsData
local middleIndex, evenNumber = stats.getMiddleIndex(statsDataCount)
local quartile1, quartile3
-- 1,2,3,4
if evenNumber then
quartile1 = stats.median(statsData, 1, middleIndex)
quartile3 = stats.median(statsData, middleIndex + 1, #statsData)
else
-- 1,2,3,4,5
-- odd number
quartile1 = stats.median(statsData, 1, middleIndex)
quartile3 = stats.median(statsData, middleIndex, #statsData)
end
return quartile1, quartile3, quartile3 - quartile1
end
function stats.getLowerAndUpperPercentages(percentage)
local function getPercent(percentage)
if type(percentage) == "number" and percentage >= 0 then
local floatPercentage = percentage / 100
return tonumber(string.format("%.2f", floatPercentage))
else
return nil -- Invalid input
end
end
local lowerPercent = getPercent(percentage)
local upperPercent = getPercent(100 - percentage)
return lowerPercent, upperPercent
end
function stats.getUpperLowerPercentileIndexes(statsData, percentage)
local lowerPercent, upperPercent = stats.getLowerAndUpperPercentages(percentage)
local lowerIndex = zo_ceil(#statsData * lowerPercent)
local upperIndex = zo_ceil(#statsData * upperPercent)
return lowerIndex, upperIndex
end
function stats.getUpperLowerContextFactors(statsData, percentage)
local lowerIndex, upperIndex = stats.getUpperLowerPercentileIndexes(statsData, percentage)
local lowerContextFactor = statsData[lowerIndex]
local upperContextFactor = statsData[upperIndex]
return lowerContextFactor, upperContextFactor
end
MasterMerchant.stats = stats
-- /script MasterMerchant:GetTooltipStats("|H1:item:54173:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h", true)
-- /script MasterMerchant:dm("Debug", MasterMerchant:GetTooltipStats("|H1:item:54484:369:50:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h", true))
-- GetItemLinkItemId("|H0:item:54484:369:50:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h")
-- 54484 50:16:4:0:0
-- |H1:item:54484:369:50:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h 50 sales
-- |H1:item:54173:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h gold mat 3000+ sales
-- /script LibPrice.ItemLinkToPriceGold("|H1:item:54173:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h", "mm")
-- LibGuildStore_Internal.GetOrCreateIndexFromLink("|H0:item:54484:369:50:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h")
-- MasterMerchant:GetTooltipStats(54484, "50:16:4:0:0", false, true)
-- Computes the weighted moving average across available data
-- /script mmUtils:ClearItemCacheById(54173, "1:0:5:0:0")
-- /script mmUtils:ClearBonanzaCacheById(54173, "1:0:5:0:0")
-- Vamp Fang |H1:item:64210:177:50:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h -- 1 bonanza listing no price to chat
-- hide scraps |H1:item:71239:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h -- 1 bonanza listing no price to chat
function MasterMerchant:GetTooltipStats(itemLink, averageOnly, generateGraph)
-- MasterMerchant:dm("Debug", "GetTooltipStats")
-- MasterMerchant:dm("Debug", itemLink)
-- 10000 for numDays is more or less like saying it is undefined, or all
--[[TODO why is there a days range of 10000. I get that it kinda means
all days but the daysHistory seems to be the actual number to be using.
For example when you press SHIFT or CTRL then daysHistory and daysRange
are the same. However, when you do not modify the data, then daysRange
is 10000 and daysHistory is however many days you have.
Answer: because daysRange is 10000 the previous authors multiplied that with
ZO_ONE_DAY_IN_SECONDS to ensure that all the sales were displayed.
]]--
-- setup early local variables
local zScoreThreshold = 2.054
local maxDeviation = 2.7
local iqrMultiplier = 1.5
local iqrThreshold = 3 -- Minimum threshold for data set size to apply IQR
local useOuterPercentile = MasterMerchant.systemSavedVariables.trimOutliersWithPercentile
local ignoreOutliers = MasterMerchant.systemSavedVariables.trimOutliers
local percentage = MasterMerchant.systemSavedVariables.outlierPercentile
local trimAgressive = MasterMerchant.systemSavedVariables.trimOutliersAgressive
local outliersList = {}
local bonanzaList = {}
local statsData = {}
local bonanzaStatsData = {}
local statsDataCount
local bonanzaStatsDataCount
local versionData
local salesData
local avgPrice = nil
local legitSales = nil
local daysHistory = MM_DAYS_RANGE_ALL
local countSold = nil
local bonanzaPrice = nil
local bonanzaListings = nil
local bonanzaItemCount = nil
local oldestTime = nil
local lowPrice = nil
local highPrice = nil
local salesPoints = nil
local currentGuild = nil
local currentBuyer = nil
local currentSeller = nil
local nameString = nil
local salesDetails = true
averageOnly = averageOnly or false
local nameInBlacklist = false
local numVouchers = 0
local graphInfo = nil
local updateItemCache = false
local updateBonanzaCache = false
local updateGraphinfoCache = false
local hasSales = false
local hasListings = false
-- set timeCheck and daysRange for cache and tooltips
local timeCheck, daysRange = self:CheckTimeframe()
if daysRange ~= MM_DAYS_RANGE_ALL then daysHistory = daysRange end
local returnData = { ['avgPrice'] = avgPrice, ['numSales'] = legitSales, ['numDays'] = daysHistory, ['numItems'] = countSold,
['bonanzaPrice'] = bonanzaPrice, ['bonanzaListings'] = bonanzaListings, ['bonanzaItemCount'] = bonanzaItemCount, ['numVouchers'] = numVouchers,
['graphInfo'] = graphInfo }
if not MasterMerchant.isInitialized or not itemLink or timeCheck == MM_DAYS_RANGE_NONE then
return returnData
end
if not MasterMerchant.systemSavedVariables.showGraph then
generateGraph = false
end
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
local itemType, specializedItemType = GetItemLinkItemType(itemLink)
local function IsNameInBlacklist()
local blacklistTable = MasterMerchant.blacklistTable
if blacklistTable == nil then return false end
return (currentGuild and blacklistTable[currentGuild]) or
(currentBuyer and blacklistTable[currentBuyer]) or
(currentSeller and blacklistTable[currentSeller])
end
local function GetTimeString(timestamp)
local formattedString = nil
local quotient, remainder = math.modf((GetTimeStamp() - timestamp) / ZO_ONE_DAY_IN_SECONDS)
if MasterMerchant.systemSavedVariables.useFormatedTime then
formattedString = MasterMerchant.TextTimeSince(timestamp)
else
if quotient == 0 then
formattedString = GetString(MM_INDEX_TODAY)
elseif quotient == 1 then
formattedString = GetString(MM_INDEX_YESTERDAY)
elseif quotient >= 2 then
formattedString = string.format(GetString(SK_TIME_DAYSAGO), quotient)
end
end
return formattedString
end
-- local function for processing the dots on the graph
local function ProcessDots(individualSale, item)
salesPoints = salesPoints or {}
local tooltip = nil
local timeframeString = ""
local stringPrice = self.LocalizedNumber(individualSale)
--[[ salesDetails means to add a detailed tooltip to the dot ]]--
if salesDetails then
timeframeString = GetTimeString(item.timestamp)
if item.quant == 1 then
tooltip = timeframeString .. " " .. string.format(GetString(MM_GRAPH_TIP_SINGLE), currentGuild,
currentSeller, nameString, currentBuyer, stringPrice)
else
tooltip = timeframeString .. " " .. string.format(GetString(MM_GRAPH_TIP), currentGuild, currentSeller,
nameString, item.quant, currentBuyer, stringPrice)
end
else
-- not detailed
tooltip = stringPrice .. MM_COIN_ICON_NO_SPACE
end
salesPoints[#salesPoints + 1] = { item.timestamp, individualSale, tooltip, currentGuild, currentSeller }
updateGraphinfoCache = true
end
local function ProcessSalesInfo(item)
local individualSale = item.price / item.quant
if countSold == nil then countSold = 0 end
countSold = countSold + item.quant
if avgPrice == nil then avgPrice = 0 end
avgPrice = avgPrice + item.price
if legitSales == nil then legitSales = 0 end
legitSales = legitSales + 1
if lowPrice == nil then lowPrice = individualSale else lowPrice = zo_min(lowPrice, individualSale) end
if highPrice == nil then highPrice = individualSale else highPrice = zo_max(highPrice, individualSale) end
if generateGraph then ProcessDots(individualSale, item) end -- end skip dots
end
local function ProcessBonanzaSale(item)
if bonanzaItemCount == nil then bonanzaItemCount = 0 end
if bonanzaPrice == nil then bonanzaPrice = 0 end
if bonanzaListings == nil then bonanzaListings = 0 end
bonanzaItemCount = bonanzaItemCount + item.quant
bonanzaPrice = bonanzaPrice + item.price
bonanzaListings = bonanzaListings + 1
end
local function BuildOutliersList(item)
outliersList[#outliersList + 1] = item
end
--[[Reminder the Bonanza Stats Data is built in
RemoveListingsPerBlacklist. We just have to sort
the Bonanza Stats Data.
]]--
local function BuildStatsData(item)
local individualSale = item.price / item.quant
statsData[#statsData + 1] = individualSale
end
local function SortStatsData()
statsDataCount = #statsData
table.sort(statsData)
end
local function SortBonanzaStatsData()
bonanzaStatsDataCount = #bonanzaStatsData
table.sort(bonanzaStatsData)
end
local function AssignOldestTimestamp(timestamp)
if oldestTime == nil or oldestTime > timestamp then oldestTime = timestamp end
end
local function ProcessItemWithTimestamp(item, useDaysRange, buildOutliersAndStats)
local isValidTimeDate = not useDaysRange or item.timestamp > timeCheck
if isValidTimeDate then
AssignOldestTimestamp(item.timestamp)
if (ignoreOutliers or useOuterPercentile) and buildOutliersAndStats then
BuildOutliersList(item)
else
ProcessSalesInfo(item)
end
if buildOutliersAndStats then
BuildStatsData(item)
end
end
end
local function FilterOutliers(item, calculatedStatsData)
-- useOuterPercentile, MasterMerchant.systemSavedVariables.trimOutliersWithPercentile
-- trimAgressive, MasterMerchant.systemSavedVariables.trimOutliersAgressive
-- dataCount, mean, stdev, quartile1, quartile3, quartileRange, madThreshold, lowerPercentile, upperPercentile
local mean = calculatedStatsData.mean
local stdev = calculatedStatsData.stdev
local quartile1, quartile3, quartileRange = calculatedStatsData.quartile1, calculatedStatsData.quartile3, calculatedStatsData.quartileRange
local madThreshold = calculatedStatsData.madThreshold
local isIQRApplicable = calculatedStatsData.dataCount >= iqrThreshold
local lowerPercentile, upperPercentile = calculatedStatsData.lowerPercentile, calculatedStatsData.upperPercentile
local individualSale = item.price / item.quant
local zScore = stats.zscore(individualSale, mean, stdev)
local isWithinMadThreshold = individualSale <= madThreshold
local isZScoreValid = zScore <= zScoreThreshold and zScore >= -zScoreThreshold
-- when trimAgressive is false then isWithinMadThreshold is ignored by making it true, regardless of the calculation
if not trimAgressive then isWithinMadThreshold = true end
if useOuterPercentile then
local isWithinPercentile = individualSale >= lowerPercentile and individualSale <= upperPercentile
if isWithinPercentile then
return true
end
elseif ignoreOutliers then
if isIQRApplicable then
local isWithinIQR = individualSale >= quartile1 - iqrMultiplier * quartileRange and individualSale <= quartile3 + iqrMultiplier * quartileRange
if isWithinIQR and isWithinMadThreshold and isZScoreValid then
return true
end
else
if isWithinMadThreshold and isZScoreValid then
return true
end
end
end
return false
end
-- 10000 for numDays is more or less like saying it is undefined
--[[TODO why is there a days range of 10000. I get that it kinda means
all days but the daysHistory seems to be the actual number to be using.
For example when you press SHIFT or CTRL then daysHistory and daysRange
are the same. However, when you do not modify the data, then daysRange
is 10000 and daysHistory is however many days you have.
]]--
salesDetails = MasterMerchant.systemSavedVariables.displaySalesDetails
-- make sure we have a list of sales to work with
hasSales = MasterMerchant:itemIDHasSales(itemID, itemIndex)
hasListings = MasterMerchant:itemIDHasListings(itemID, itemIndex)
local hasSalesPrice = mmUtils:ItemCacheHasPriceInfoById(itemID, itemIndex, daysRange)
local hasBonanzaPrice = mmUtils:BonanzaCacheHasPriceInfoById(itemID, itemIndex, daysRange)
local hasGraphinfo = mmUtils:CacheHasGraphInfoById(itemID, itemIndex, daysRange)
local createGraph = generateGraph and not hasGraphinfo
if hasSales and (not hasSalesPrice or createGraph) then
versionData = sales_data[itemID][itemIndex]
salesData = versionData['sales']
nameString = versionData.itemDesc
oldestTime = versionData.oldestTime
--[[1-2-2021 Our sales data is now ready to be trimmed if
trim outliers is active.
]]--
--[[1-2-2021 We have determined that there is more then one sale
in the table and the dayshistory using the daysrange.
We can now trim outliers if the uses has that active
]]--
--[[1-2-2021 First we will see if the data is already
calculated.
1-2-2021 Needs updated
local lookupDataFound = dataPresent(itemID, itemIndex, daysRange)
12-11-2022 Old 'daysHistory = daysRange' moved above for tooltips
]]--
if (daysRange == MM_DAYS_RANGE_ALL) then
local quotient, remainder = math.modf((GetTimeStamp() - oldestTime) / ZO_ONE_DAY_IN_SECONDS)
daysHistory = quotient + zo_floor(0.5 + remainder)
end
local useDaysRange = daysRange ~= MM_DAYS_RANGE_ALL
oldestTime = nil
-- start loop for non outliers
for _, item in pairs(salesData) do
currentGuild = internal:GetGuildNameByIndex(item.guild)
currentBuyer = internal:GetAccountNameByIndex(item.buyer)
currentSeller = internal:GetAccountNameByIndex(item.seller)
nameInBlacklist = IsNameInBlacklist()
local shouldUseSale = MasterMerchant:ShouldUseSale(item.id)
if not nameInBlacklist and shouldUseSale then
ProcessItemWithTimestamp(item, useDaysRange, true)
end
end -- end for loop for non outliers
SortStatsData()
if ignoreOutliers or useOuterPercentile then
if (outliersList and next(outliersList)) and (statsDataCount and statsDataCount > 0) then
oldestTime = nil
local madThreshold = stats.calculateMADThreshold(statsData, maxDeviation)
local mean = stats.mean(statsData)
local stdev = stats.standardDeviation(statsData)
local quartile1, quartile3, quartileRange = stats.interquartileRange(statsData)
local lowerPercentile, upperPercentile = stats.getUpperLowerContextFactors(statsData, percentage)
local calculatedStatsData = {
dataCount = statsDataCount,
mean = mean,
stdev = stdev,
quartile1 = quartile1,
quartile3 = quartile3,
quartileRange = quartileRange,
madThreshold = madThreshold,
lowerPercentile = lowerPercentile,
upperPercentile = upperPercentile,
}
for _, item in pairs(outliersList) do
currentGuild = internal:GetGuildNameByIndex(item.guild)
currentBuyer = internal:GetAccountNameByIndex(item.buyer)
currentSeller = internal:GetAccountNameByIndex(item.seller)
local nonOutlier = FilterOutliers(item, calculatedStatsData)
if nonOutlier then
ProcessItemWithTimestamp(item, useDaysRange, false)
end
end
end
end -- end trim outliers
if legitSales and legitSales >= 1 then
avgPrice = avgPrice / countSold
--[[found an average price of 0.07 which X 200 is 14g
even 0.01 X 200 is 2g
]]--
if avgPrice < 0.01 then avgPrice = 0.01 end
end
if avgPrice then updateItemCache = true end
end
if hasListings and (not hasBonanzaPrice and not averageOnly) then
bonanzaList = listings_data[itemID][itemIndex]['sales']
bonanzaList, bonanzaStatsData = RemoveListingsPerBlacklist(bonanzaList)
SortBonanzaStatsData()
if (bonanzaList and next(bonanzaList)) and (bonanzaStatsDataCount and bonanzaStatsDataCount > 0) then
local madThreshold = stats.calculateMADThreshold(bonanzaStatsData, maxDeviation)
local mean = stats.mean(bonanzaStatsData)
local stdev = stats.standardDeviation(bonanzaStatsData)
local quartile1, quartile3, quartileRange = stats.interquartileRange(bonanzaStatsData)
local lowerPercentile, upperPercentile = stats.getUpperLowerContextFactors(bonanzaStatsData, percentage)
local calculatedStatsData = {
dataCount = bonanzaStatsDataCount,
mean = mean,
stdev = stdev,
quartile1 = quartile1,
quartile3 = quartile3,
quartileRange = quartileRange,
madThreshold = madThreshold,
lowerPercentile = lowerPercentile,
upperPercentile = upperPercentile,
}
for _, item in pairs(bonanzaList) do
local nonOutlier = FilterOutliers(item, calculatedStatsData)
if nonOutlier then
ProcessBonanzaSale(item)
end
end
if bonanzaListings and bonanzaListings >= 1 then
bonanzaPrice = bonanzaPrice / bonanzaItemCount
--[[found an average price of 0.07 which X 200 is 14g
even 0.01 X 200 is 2g
]]--
if bonanzaPrice and bonanzaPrice < 0.01 then bonanzaPrice = 0.01 end
end
if bonanzaPrice then updateBonanzaCache = true end
end
--[[
if MasterMerchant.systemSavedVariables.useLibDebugLogger and (bonanzaPrice == nil or (bonanzaItemCount == nil and bonanzaListings == nil)) then
MasterMerchant:dm("Warn", "Examine this Bonanza data to see if it is accurate.")
if next(bonanzaList) then
if #bonanzaList <= 10 then
MasterMerchant:dm("Debug", "bonanzaList", bonanzaList)
MasterMerchant:dm("Debug", "bonanzaStatsData", bonanzaStatsData)
end
end
MasterMerchant:dm("Debug", "bonanzaPrice", bonanzaPrice)
MasterMerchant:dm("Debug", "bonanzaListings", bonanzaListings)
MasterMerchant:dm("Debug", "bonanzaItemCount", bonanzaItemCount)
bonanzaPrice = nil
bonanzaListings = nil
bonanzaItemCount = nil
end
]]--
end
if itemType == ITEMTYPE_MASTER_WRIT and (MasterMerchant.systemSavedVariables.includeVoucherAverageTooltip or MasterMerchant.systemSavedVariables.includeVoucherAveragePTC) then
numVouchers = mmUtils:GetVoucherCountByItemLink(itemLink)
end
-- Retrieve Item (['sales']) information including graph if hasSalesPrice and not generating new graphInfo
if hasSalesPrice and not createGraph then
local itemInfo = mmUtils:GetItemCacheStats(itemLink, daysRange)
if itemInfo then
avgPrice = itemInfo.avgPrice
legitSales = itemInfo.numSales
daysHistory = itemInfo.numDays
countSold = itemInfo.numItems
numVouchers = itemInfo.numVouchers
local graphInformation = itemInfo.graphInfo
if graphInformation then
oldestTime = graphInformation.oldestTime
lowPrice = graphInformation.low
highPrice = graphInformation.high
salesPoints = graphInformation.points
end
end
end
-- Retrieve Bonanza (['listings']) information from the cache if we aren't generating it again
-- not verified
if hasBonanzaPrice then
local itemInfo = mmUtils:GetBonanzaCacheStats(itemLink, daysRange)
if itemInfo then
bonanzaPrice = itemInfo.bonanzaPrice
bonanzaListings = itemInfo.bonanzaListings
bonanzaItemCount = itemInfo.bonanzaItemCount
end
end
-- Setup Graphinfo if salesPoints exists
if salesPoints then
graphInfo = { oldestTime = oldestTime, low = lowPrice, high = highPrice, points = salesPoints }
end
-- Assign Item (['sales']) information to the cache
if hasSales and updateItemCache then
local itemInfo = {
avgPrice = avgPrice,
numSales = legitSales,
numDays = daysHistory,
numItems = countSold,
numVouchers = numVouchers,
}
mmUtils:SetItemCacheById(itemID, itemIndex, daysRange, itemInfo)
end
-- Assign Bonanza (['listings']) information to the cache
if hasListings and updateBonanzaCache then
local itemInfo = {
bonanzaPrice = bonanzaPrice,
bonanzaListings = bonanzaListings,
bonanzaItemCount = bonanzaItemCount,
}
mmUtils:SetBonanzaCacheById(itemID, itemIndex, daysRange, itemInfo)
end
-- Assign Graphinfo to the Item (['sales']) Cache
if hasSales and salesPoints and updateGraphinfoCache then
if legitSales and legitSales > 1500 then
mmUtils:SetGraphInfoCacheById(itemID, itemIndex, daysRange, graphInfo)
end
end
returnData = { ['avgPrice'] = avgPrice, ['numSales'] = legitSales, ['numDays'] = daysHistory, ['numItems'] = countSold, ['numVouchers'] = numVouchers,
['bonanzaPrice'] = bonanzaPrice, ['bonanzaListings'] = bonanzaListings, ['bonanzaItemCount'] = bonanzaItemCount,
['graphInfo'] = graphInfo }
return returnData
end
function MasterMerchant:itemIDHasSales(itemID, itemIndex)
local salesData = sales_data[itemID] and sales_data[itemID][itemIndex]
if salesData and salesData.sales then
return salesData.totalCount > 0
end
return false
end
function MasterMerchant:itemLinkHasSales(itemLink)
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
return MasterMerchant:itemIDHasSales(itemID, itemIndex)
end
function MasterMerchant:itemIDHasListings(itemID, itemIndex)
local itemData = listings_data[itemID] and listings_data[itemID][itemIndex]
if itemData then
return itemData.totalCount > 0
end
return false
end
function MasterMerchant:itemLinkHasListings(itemLink)
local itemID = GetItemLinkItemId(itemLink)
local itemIndex = internal.GetOrCreateIndexFromLink(itemLink)
return MasterMerchant:itemIDHasListings(itemID, itemIndex)
end
-- /script d(MasterMerchant:GetTradeSkillInformation("|H1:item:33825:3:1:0:0:0:0:0:0:0:0:0:0:0:0:0:1:0:0:0:0|h|h"))
-- /script MasterMerchant:itemCraftPrice("|H1:item:68195:5:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h")
function MasterMerchant:GetTradeSkillInformation(itemLink)
local MM_TRADESKILL_ALCHEMY = 77
local MM_TRADESKILL_PROVISIONING = 76
local ITEMTYPE_TO_ABILITYINDEX = {
[ITEMTYPE_POISON] = 4,
[ITEMTYPE_POTION] = 4,
[ITEMTYPE_FOOD] = 5,
[ITEMTYPE_DRINK] = 6,
}
local SPECIALIZED_ITEMTYPE_TO_ABILITYINDEX = {
[SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_FOOD] = 5,
[SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_DRINK] = 6,
}
local itemType, specializedItemType = GetItemLinkItemType(itemLink)
local skillAbilityIndex = ITEMTYPE_TO_ABILITYINDEX[itemType]
if (itemType == ITEMTYPE_RECIPE and (specializedItemType == SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_FOOD or specializedItemType == SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_DRINK)) then
skillAbilityIndex = SPECIALIZED_ITEMTYPE_TO_ABILITYINDEX[specializedItemType]
end
local craftingType = MM_TRADESKILL_PROVISIONING
if itemType == ITEMTYPE_POTION or itemType == ITEMTYPE_POISON then
craftingType = MM_TRADESKILL_ALCHEMY
end
local numSkillLines = GetNumSkillLines(SKILL_TYPE_TRADESKILL)
for sl = 1, numSkillLines do
local skillLineId = GetSkillLineId(SKILL_TYPE_TRADESKILL, sl)
if skillLineId == craftingType then
local numAbilities = GetNumSkillAbilities(SKILL_TYPE_TRADESKILL, sl)
for ab = 1, numAbilities do
if ab == skillAbilityIndex then
local _, _, _, _, _, purchased, _, rank = GetSkillAbilityInfo(SKILL_TYPE_TRADESKILL, sl, ab)
return purchased, rank
end
end
end --
end
return false, 0
end
-- /script d(MasterMerchant:GetSkillLineProvisioningAlchemyRank("|H1:item:33825:3:1:0:0:0:0:0:0:0:0:0:0:0:0:0:1:0:0:0:0|h|h"))
--[[ input: Item link of the Provisioning or Alchemy item. For example the crafted
Grape Preserves not the Recipe ]]--
function MasterMerchant:GetSkillLineProvisioningAlchemyRank(itemLink)
local multiplier = 1 -- you can't divide by 0
local purchaced, skillRank = MasterMerchant:GetTradeSkillInformation(itemLink)
local itemType, specializedItemType = GetItemLinkItemType(itemLink)
if purchaced then
if itemType == ITEMTYPE_POTION or itemType == ITEMTYPE_FOOD or itemType == ITEMTYPE_DRINK or (itemType == ITEMTYPE_RECIPE and (specializedItemType == SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_FOOD or specializedItemType == SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_DRINK)) then
multiplier = skillRank + 1
elseif itemType == ITEMTYPE_POISON then
multiplier = (skillRank + 1) * 4
end
end
if not purchaced and itemType == ITEMTYPE_POISON then
multiplier = 4
end
return multiplier
end
-- /script MasterMerchant:itemCraftPrice("|H1:item:68195:5:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h")
-- |H1:item:189488:5:1:0:0:0:0:0:0:0:0:0:0:0:0:0:1:0:0:0:0|h|h
-- |H1:item:190086:5:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h
function MasterMerchant:itemCraftPrice(itemLink)
local itemType, specializedItemType = GetItemLinkItemType(itemLink)
local multiplier = MasterMerchant:GetSkillLineProvisioningAlchemyRank(itemLink)
if (itemType == ITEMTYPE_POTION) or (itemType == ITEMTYPE_POISON) then
if not IsItemLinkCrafted(itemLink) then
return nil, nil
end
local effect1, effect2, effect3, effect4 = LibAlchemy:GetEffectsFromItemLink(itemLink)
local solventItemLink = MasterMerchant:GetSolventItemLink(itemLink)
if effect1 ~= 0 then
local cost = MasterMerchant.GetItemLinePrice(solventItemLink)
local bestIngredients = LibAlchemy:getBestCombination({ LibAlchemy.effectsByWritID[effect1], LibAlchemy.effectsByWritID[effect2], LibAlchemy.effectsByWritID[effect3], LibAlchemy.effectsByWritID[effect4] }) or {}
for _, itemId in pairs(bestIngredients) do
local ingredientItemLink = string.format('|H1:item:%d:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h', itemId)
cost = cost + MasterMerchant.GetItemLinePrice(ingredientItemLink)
end
return cost, (cost / multiplier)
else
return nil, nil
end
end
local numIngredients = MasterMerchant.GetItemLinkRecipeNumIngredients(itemLink)
if ((numIngredients or 0) == 0) then
-- Try to clean up item link by moving it to level 1
itemLink = itemLink:gsub(":0", ":1", 1)
numIngredients = MasterMerchant.GetItemLinkRecipeNumIngredients(itemLink)
end
if ((numIngredients or 0) > 0) then
local cost = 0
for i = 1, numIngredients do
local ingredientItemLink, numRequired = MasterMerchant.GetItemLinkRecipeIngredientInfo(itemLink, i)
if ingredientItemLink then
cost = cost + (MasterMerchant.GetItemLinePrice(ingredientItemLink) * numRequired)
end
end
if ((itemType == ITEMTYPE_DRINK) or (itemType == ITEMTYPE_FOOD)
or (itemType == ITEMTYPE_RECIPE and (specializedItemType == SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_FOOD or specializedItemType == SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_DRINK))) then
return cost, (cost / multiplier)
end
return cost, nil
else
return nil, nil
end
end
function MasterMerchant.loadRecipesFrom(startNumber, endNumber)
local checkTime = GetGameTimeMilliseconds()
local recNumber = startNumber - 1
local resultLink
local itemLink
while true do
recNumber = recNumber + 1
itemLink = string.format('|H1:item:%d:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h', recNumber)
local itemType = GetItemLinkItemType(itemLink)
if itemType == ITEMTYPE_ENCHANTING_RUNE_ESSENCE then
table.insert(MasterMerchant.essenceRunes, recNumber)
elseif itemType == ITEMTYPE_ENCHANTING_RUNE_POTENCY then
table.insert(MasterMerchant.potencyRunes, recNumber)
elseif itemType == ITEMTYPE_ENCHANTING_RUNE_ASPECT then
table.insert(MasterMerchant.aspectRunes, recNumber)
elseif itemType == ITEMTYPE_POTION_BASE then
local levelRequired = GetItemLinkRequiredLevel(itemLink) + GetItemLinkRequiredChampionPoints(itemLink)
MasterMerchant.potionSolvents[levelRequired] = recNumber
MasterMerchant.potionSolventsItemLinks[recNumber] = MasterMerchant.potionSolventsItemLinks[recNumber] or {}
MasterMerchant.potionSolventsItemLinks[recNumber][levelRequired] = MasterMerchant.potionSolventsItemLinks[recNumber][levelRequired] or {}
MasterMerchant.potionSolventsItemLinks[recNumber][levelRequired][1] = itemLink
elseif itemType == ITEMTYPE_POISON_BASE then
local levelRequired = GetItemLinkRequiredLevel(itemLink) + GetItemLinkRequiredChampionPoints(itemLink)
MasterMerchant.poisonSolvents[levelRequired] = recNumber
MasterMerchant.poisonSolventsItemLinks[recNumber] = MasterMerchant.poisonSolventsItemLinks[recNumber] or {}
MasterMerchant.poisonSolventsItemLinks[recNumber][levelRequired] = MasterMerchant.poisonSolventsItemLinks[recNumber][levelRequired] or {}
MasterMerchant.poisonSolventsItemLinks[recNumber][levelRequired][2] = itemLink
elseif itemType == ITEMTYPE_REAGENT then
table.insert(MasterMerchant.reagents, recNumber)
MasterMerchant.reagentItemLinks[recNumber] = MasterMerchant.reagentItemLinks[recNumber] or {}
MasterMerchant.reagentItemLinks[recNumber][2] = itemLink
--[[
MasterMerchant.reagents[recNumber] = {}
for i = 1, GetMaxTraits() do
local _, traitName = GetItemLinkReagentTraitInfo(itemLink, i)
table.insert(MasterMerchant.reagents[recNumber], traitName)
-- If you get an error here, you don't know all the flower/rune traits....
MasterMerchant.traits[traitName] = MasterMerchant.traits[traitName] or {}
table.insert(MasterMerchant.traits[traitName], recNumber)
end
--]]
elseif itemType == ITEMTYPE_RECIPE then
resultLink = GetItemLinkRecipeResultItemLink(itemLink)
if (resultLink ~= MM_STRING_EMPTY) then
MasterMerchant.recipeData[resultLink] = itemLink
MasterMerchant.recipeCount = MasterMerchant.recipeCount + 1