This answer is not as beautiful as kglr's solution, my main focus is functionality. You can predict an offer is good or not, base on the number that appears below the input form (chance of opening a better case). (after you enter the offer click
somewhere. if you press enter
, the result will be duplicated)
If you hover on each step, all the necessary information at that step appears, including:
- Step + (offer)
- Statistics of closed cases
- Total amount of closed and opened cases
- Chance of winning 1M and over 100K
If that step has an offer, the label will show that too:
openedCases = {};
(* defined data *)
prices = {0.01, 1, 5, 10, 25, 50, 75, 100, 200, 300, 400, 500, 750,
1000, 5000, 10000, 25000, 50000, 75000, 100000, 200000, 300000,
400000, 500000, 750000, 1000000};
offerPos = {6, 11, 15, 18, 20, 21, 22, 23, 24, 25};
offers = ConstantArray[0, Length@prices];
(* function to calculate chance of con function over data *)
chance[data_, con_] :=
ToString@Round[100*Count[data, c_ /; con@c]/Length@data, .01] <> " %"
(* function to generate BoxWhisker labels *)
label[data_, index_, label_] := Module[{hasOffer, divideLineIndicies},
hasOffer = MemberQ[offerPos, index[[2]]];
divideLineIndicies = {{2}, {7}, {10}};
If[hasOffer, divideLineIndicies += 1];
Grid[{{"Step:", Last@index},
If[hasOffer, {"Offer:", Dynamic@offers[[index[[2]]]]},
Nothing], {"Max:", Max[data]}, {"75%:",
Quantile[data, 3/4]}, {"Median:", N@Mean[data]}, {"25%:",
Quantile[data, 1/4]}, {"Min:",
Min[data]}, {"Cases"}, {"Closed:",
AccountingForm@Total[data]}, {"Opened:",
Total@prices - Total@data}, {"Chances"}, {"1 M:",
chance[data, # == 10^6 &]}, {">100K:",
chance[data, # >= 10^5 &]}}, Alignment -> {{Right, Left}},
Dividers -> {{False},
ReplacePart[ConstantArray[False, 13],
divideLineIndicies -> True]}] /.
n_Real | n_Integer /; n > 1000 :>
NumberForm[n, DigitBlock -> 3,
ScientificNotationThreshold -> {-7, 7}]]
Manipulate[
notOpened =
MapIndexed[Complement[prices, openedCases[[;; #2[[1]]]]] &,
openedCases];
If[Length@openedCases >= offerN,
temp = Complement[prices, openedCases[[;; offerN]]], temp = {0}];
Show[
BoxWhiskerChart[notOpened,
LabelingFunction -> (Placed[label[##], Tooltip] &)],
ListLinePlot[Mean /@ notOpened, PlotStyle -> Red],
ListPlot[offers[[;; Length@openedCases]] /. {0 -> Indeterminate},
PlotStyle -> Red, PlotMarkers -> {"-", Large}],
Frame -> {{True, False}, {False, False}},
PlotRange -> {Automatic, {0, Max@prices}}],
Row@{
TogglerBar[Dynamic[openedCases], prices,
Appearance -> "Vertical" -> {Automatic, 2}],
, Spacer[5],
Grid@{
{"Offer N", "Value"},
{PopupMenu[Dynamic@offerN, offerPos],
InputField[Dynamic@offers[[offerN]], Number]},
{"",
Row[{"Chance of getting a better case: ",
N@Dynamic[
Count[temp, p_ /; p > offers[[offerN]]]*100/Length@temp],
" %"}]}}}]