@ -1,18 +1,18 @@
//Reusable Fields
const getSellFields = function ( ) {
let fields = [ ]
let fields = [ ] ;
for ( var i = 2 ; i < 14 ; i ++ ) {
fields . push ( $ ( "#sell_" + i ) [ 0 ] )
fields . push ( $ ( "#sell_" + i ) [ 0 ] ) ;
}
return fields
}
return fields ;
} ;
const getFirstBuyRadios = function ( ) {
return [
$ ( "#first-time-radio-no" ) [ 0 ] ,
$ ( "#first-time-radio-yes" ) [ 0 ]
] ;
}
} ;
const getPreviousPatternRadios = function ( ) {
return [
@ -22,11 +22,11 @@ const getPreviousPatternRadios = function () {
$ ( "#pattern-radio-large-spike" ) [ 0 ] ,
$ ( "#pattern-radio-decreasing" ) [ 0 ]
] ;
}
} ;
const getCheckedRadio = function ( radio _array ) {
return radio _array . find ( radio => radio . checked === true ) . value ;
}
} ;
const checkRadioByValue = function ( radio _array , value ) {
if ( value === null ) {
@ -34,15 +34,15 @@ const checkRadioByValue = function (radio_array, value) {
}
value = value . toString ( ) ;
radio _array . find ( radio => radio . value == value ) . checked = true ;
}
} ;
const sell _inputs = getSellFields ( )
const buy _input = $ ( "#buy" )
const first _buy _radios = getFirstBuyRadios ( )
const previous _pattern _radios = getPreviousPatternRadios ( )
const permalink _input = $ ( '#permalink-input' )
const permalink _button = $ ( '#permalink-btn' )
const snackbar = $ ( '#snackbar' )
const sell _inputs = getSellFields ( ) ;
const buy _input = $ ( "#buy" ) ;
const first _buy _radios = getFirstBuyRadios ( ) ;
const previous _pattern _radios = getPreviousPatternRadios ( ) ;
const permalink _input = $ ( '#permalink-input' ) ;
const permalink _button = $ ( '#permalink-btn' ) ;
const snackbar = $ ( '#snackbar' ) ;
//Functions
const fillFields = function ( prices , first _buy , previous _pattern ) {
@ -50,21 +50,21 @@ const fillFields = function (prices, first_buy, previous_pattern) {
checkRadioByValue ( previous _pattern _radios , previous _pattern ) ;
buy _input . focus ( ) ;
buy _input . val ( prices [ 0 ] || '' )
buy _input . val ( prices [ 0 ] || '' ) ;
buy _input . blur ( ) ;
const sell _prices = prices . slice ( 2 )
const sell _prices = prices . slice ( 2 ) ;
sell _prices . forEach ( ( price , index ) => {
if ( ! price ) {
return
return ;
} else {
const element = $ ( "#sell_" + ( index + 2 ) ) ;
element . focus ( ) ;
element . val ( price ) ;
element . blur ( ) ;
}
} )
}
} ) ;
} ;
const initialize = function ( ) {
try {
@ -73,9 +73,9 @@ const initialize = function () {
const previous _pattern = previous [ 1 ] ;
const prices = previous [ 2 ] ;
if ( prices === null ) {
fillFields ( [ ] , first _buy , previous _pattern )
fillFields ( [ ] , first _buy , previous _pattern ) ;
} else {
fillFields ( prices , first _buy , previous _pattern )
fillFields ( prices , first _buy , previous _pattern ) ;
}
} catch ( e ) {
console . error ( e ) ;
@ -83,32 +83,32 @@ const initialize = function () {
$ ( document ) . trigger ( "input" ) ;
$ ( "#permalink-btn" ) . on ( "click" , copyPermalink )
$ ( "#permalink-btn" ) . on ( "click" , copyPermalink ) ;
$ ( "#reset" ) . on ( "click" , function ( ) {
if ( window . confirm ( i18next . t ( "prices.reset-warning" ) ) ) {
sell _inputs . forEach ( input => input . value = '' )
fillFields ( [ ] , false , - 1 )
update ( )
sell _inputs . forEach ( input => input . value = '' ) ;
fillFields ( [ ] , false , - 1 ) ;
update ( ) ;
}
} )
}
} ) ;
} ;
const updateLocalStorage = function ( prices , first _buy , previous _pattern ) {
try {
if ( prices . length !== 14 ) throw "The data array needs exactly 14 elements to be valid"
localStorage . setItem ( "sell_prices" , JSON . stringify ( prices ) )
if ( prices . length !== 14 ) throw "The data array needs exactly 14 elements to be valid" ;
localStorage . setItem ( "sell_prices" , JSON . stringify ( prices ) ) ;
localStorage . setItem ( "first_buy" , JSON . stringify ( first _buy ) ) ;
localStorage . setItem ( "previous_pattern" , JSON . stringify ( previous _pattern ) ) ;
} catch ( e ) {
console . error ( e )
console . error ( e ) ;
}
}
} ;
const isEmpty = function ( arr ) {
const filtered = arr . filter ( value => value !== null && value !== '' && ! isNaN ( value ) )
return filtered . length == 0
}
const filtered = arr . filter ( value => value !== null && value !== '' && ! isNaN ( value ) ) ;
return filtered . length == 0 ;
} ;
const getFirstBuyStateFromQuery = function ( param ) {
try {
@ -131,15 +131,15 @@ const getFirstBuyStateFromQuery = function (param) {
} catch ( e ) {
return null ;
}
}
} ;
const getFirstBuyStateFromLocalstorage = function ( ) {
return JSON . parse ( localStorage . getItem ( 'first_buy' ) )
}
return JSON . parse ( localStorage . getItem ( 'first_buy' ) ) ;
} ;
const getPreviousPatternStateFromLocalstorage = function ( ) {
return JSON . parse ( localStorage . getItem ( 'previous_pattern' ) )
}
return JSON . parse ( localStorage . getItem ( 'previous_pattern' ) ) ;
} ;
const getPreviousPatternStateFromQuery = function ( param ) {
try {
@ -167,7 +167,7 @@ const getPreviousPatternStateFromQuery = function (param) {
} catch ( e ) {
return null ;
}
}
} ;
const getPricesFromLocalstorage = function ( ) {
try {
@ -245,8 +245,8 @@ const getSellPrices = function () {
//Checks all sell inputs and returns an array with their values
return res = sell _inputs . map ( function ( input ) {
return parseInt ( input . value || '' ) ;
} )
}
} ) ;
} ;
const getPriceClass = function ( buy _price , max ) {
const priceBrackets = [ 200 , 30 , 0 , - 30 , - 99 ] ;
@ -257,7 +257,7 @@ const getPriceClass = function(buy_price, max) {
}
}
return "" ;
}
} ;
const displayPercentage = function ( fraction ) {
if ( Number . isFinite ( fraction ) ) {
@ -270,28 +270,29 @@ const displayPercentage = function(fraction) {
return '<0.01%' ;
}
} else {
return '—'
return '—' ;
}
}
} ;
const calculateOutput = function ( data , first _buy , previous _pattern ) {
if ( isEmpty ( data ) ) {
$ ( "#output" ) . html ( "" ) ;
return ;
}
let pat _desc = { 0 : "fluctuating" , 1 : "large-spike" , 2 : "decreasing" , 3 : "small-spike" , 4 : "all" } ;
let output _possibilities = "" ;
let predictor = new Predictor ( data , first _buy , previous _pattern ) ;
let analyzed _possibilities = predictor . analyze _possibilities ( ) ;
let buy _price = parseInt ( buy _input . val ( ) ) ;
previous _pattern _number = ""
previous _pattern _number = "" ;
for ( let poss of analyzed _possibilities ) {
var out _line = "<tr><td class='table-pattern'>" + poss. pattern _description + "</td>" ;
var out _line = "<tr><td class='table-pattern'>" + i18next. t ( "patterns." + pat _desc [ poss . pattern _number ] ) + "</td>" ;
const style _price = buy _price || poss . prices [ 0 ] . min ;
if ( previous _pattern _number != poss . pattern _number ) {
previous _pattern _number = poss . pattern _number
previous _pattern _number = poss . pattern _number ;
pattern _count = analyzed _possibilities
. filter ( val => val . pattern _number == poss . pattern _number )
. length
. length ;
out _line += ` <td rowspan= ${ pattern _count } > ${ displayPercentage ( poss . category _total _probability ) } </td> ` ;
}
out _line += ` <td> ${ displayPercentage ( poss . probability ) } </td> ` ;
@ -307,13 +308,13 @@ const calculateOutput = function (data, first_buy, previous_pattern) {
var min _class = getPriceClass ( style _price , poss . weekGuaranteedMinimum ) ;
var max _class = getPriceClass ( style _price , poss . weekMax ) ;
out _line += ` <td class=' ${ min _class } '> ${ poss . weekGuaranteedMinimum } </td><td class=' ${ max _class } '> ${ poss . weekMax } </td></tr> ` ;
output _possibilities += out _line
output _possibilities += out _line ;
}
$ ( "#output" ) . html ( output _possibilities )
$ ( "#output" ) . html ( output _possibilities ) ;
update _chart ( data , analyzed _possibilities ) ;
}
} ;
const generatePermalink = function ( buy _price , sell _prices , first _buy , previous _pattern ) {
let searchParams = new URLSearchParams ( ) ;
@ -337,7 +338,7 @@ const generatePermalink = function (buy_price, sell_prices, first_buy, previous_
}
return searchParams . toString ( ) && window . location . origin . concat ( '?' , searchParams . toString ( ) ) ;
}
} ;
const copyPermalink = function ( ) {
let text = permalink _input [ 0 ] ;
@ -350,17 +351,17 @@ const copyPermalink = function () {
permalink _input . hide ( ) ;
flashMessage ( i18next . t ( "prices.permalink-copied" ) ) ;
}
} ;
const flashMessage = function ( message ) {
snackbar . text ( message ) ;
snackbar . addClass ( 'show' ) ;
setTimeout ( function ( ) {
snackbar . removeClass ( 'show' )
snackbar . removeClass ( 'show' ) ;
snackbar . text ( '' ) ;
} , 3000 ) ;
}
} ;
const update = function ( ) {
const sell _prices = getSellPrices ( ) ;
@ -383,4 +384,4 @@ const update = function () {
}
calculateOutput ( prices , first _buy , previous _pattern ) ;
}
} ;