<commit_before>package se.media4u101.lib

import scala.xml.{ NodeSeq, Text }
import net.liftweb.common._
import net.liftweb.json.JsonAST._
import net.liftweb.json.JsonDSL._  
import net.liftweb.json.DefaultFormats
import net.liftweb.util.{ Props }

trait BTCRestHelper extends Loggable {

  implicit val formats = DefaultFormats
  
  lazy val forwardSplitValue = Props.getInt("revenue.forward.split", 1)
  
  /*
  def getKapitonData():JValue = {
    //logger.debug("BTCRestHelper::getKapitonData()")    
    val data = RestProxy.fetchKapitonData()
    val kdata = this.getMergedKapitonData(data)
    kdata     
  }
  */
  
  def getSlushPoolStatData():JValue = {
    //logger.debug("BTCRestHelper::getSlushPoolStat()")   
    val data = RestProxy.fetchSlushPoolStat()
    val spdata = this.getMergedSlushPoolStatData(data)
    spdata    
  }
  
  def getWalletData(userLoggedIn:Boolean):JValue = {
    //logger.debug("BTCRestHelper::getWalletData()") 
    val data = RestProxy.fetchWalletData() 
    val wdata = this.getMergedWalletData(data,userLoggedIn)  
    wdata
  }
  
  def getServerDateTime():JValue = {
    val millis = RestProxy.fetchServerSystemMillis()
    val datetime = this.getMergedServerDateTime(millis)
    datetime
  }  
  
  def getAccProfileData():JValue = {
    //logger.debug("BTCRestHelper::getAccProfileData()")
    val apdata = RestProxy.fetchAccProfileData()
    val mtgoxSEK  = RestProxy.fetchMtgoxSEK()
    val mtgoxUSD = RestProxy.fetchMtgoxUSD() 
    val mtgoxEUR = RestProxy.fetchMtgoxEUR()
    val accdata = this.getMergedAccProfileData(apdata)
    val sekdata = this.getMergedMtgoxSEKData(accdata,mtgoxSEK)
    val usddata = this.getMergedMtgoxUSDData(accdata,mtgoxUSD)
    val eurdata = this.getMergedMtgoxEURData(accdata,mtgoxEUR)
    val data = accdata merge sekdata merge usddata merge eurdata
    data
  }  
  
  /*Methods below is doing some internal calculations and json manipulations, no other external references used */
  private def getMergedServerDateTime(millis:JValue):JValue = {
    //val dateTime = this.getFormatedServerDateTime(millis)
    val dateTime = this.simpelBigIntTransform( (for {JField("btc_server_system_millis",JInt(v)) <- millis } yield v).headOption, "btc_server_dt")
    dateTime
  }
  
  /*
  private def getMergedKapitonData(kdata:JValue):JValue = {
    //logger.debug("BTCRestHelper::getMergedKapitonData()")
    val ask   = this.kaptionTickerAsk(kdata)
    val bid   = this.kaptionTickerBid(kdata)
    val hi    = this.kaptionTickerHi(kdata)
    val low   = this.kaptionTickerLow(kdata)
    val mave  = this.kaptionTickerMonthAverage(kdata)
    val mvol  = this.kaptionTickerMonthVolym(kdata)
    val price = this.kaptionTickerPrice(kdata)
    val vol   = this.kaptionTickerVol(kdata)
    val data = ask merge bid merge hi merge low merge mave merge mvol merge price merge vol
    data
  }
  */
  
  private def getMergedSlushPoolStatData(data:JValue):JValue = {
    //logger.debug("BTCRestHelper::getMergedSlushPoolStatData()")  
    val round      = this.simpelStringTransform((for { JField("round_started",JString(value)) <- data } yield value ).headOption,"sps_round_started")
    val stratum    = this.simpelStringTransform((for { JField("active_stratum",JString(active_stratum)) <- data } yield active_stratum ).headOption,"sps_active_stratum")
    val workers    = this.simpelStringTransform( (for { JField("active_workers",JString(value)) <- data } yield value ).headOption, "sps_active_workers") 
    val ghashshare = this.simpelStringTransform( (for { JField("ghashes_ps",JString(s)) <- data } yield s ).headOption, "sps_ghashes_ps")<commit_msg>Accidently formating of date time re-addingin it.<commit_after>package se.media4u101.lib

import scala.xml.{ NodeSeq, Text }
import net.liftweb.common._
import net.liftweb.json.JsonAST._
import net.liftweb.json.JsonDSL._  
import net.liftweb.json.DefaultFormats
import net.liftweb.util.{ Props }

trait BTCRestHelper extends Loggable {

  implicit val formats = DefaultFormats
  
  lazy val forwardSplitValue = Props.getInt("revenue.forward.split", 1)
  
  /*
  def getKapitonData():JValue = {
    //logger.debug("BTCRestHelper::getKapitonData()")    
    val data = RestProxy.fetchKapitonData()
    val kdata = this.getMergedKapitonData(data)
    kdata     
  }
  */
  
  def getSlushPoolStatData():JValue = {
    //logger.debug("BTCRestHelper::getSlushPoolStat()")   
    val data = RestProxy.fetchSlushPoolStat()
    val spdata = this.getMergedSlushPoolStatData(data)
    spdata    
  }
  
  def getWalletData(userLoggedIn:Boolean):JValue = {
    //logger.debug("BTCRestHelper::getWalletData()") 
    val data = RestProxy.fetchWalletData() 
    val wdata = this.getMergedWalletData(data,userLoggedIn)  
    wdata
  }
  
  def getServerDateTime():JValue = {
    val millis = RestProxy.fetchServerSystemMillis()
    val datetime = this.getMergedServerDateTime(millis)
    datetime
  }  
  
  def getAccProfileData():JValue = {
    //logger.debug("BTCRestHelper::getAccProfileData()")
    val apdata = RestProxy.fetchAccProfileData()
    val mtgoxSEK  = RestProxy.fetchMtgoxSEK()
    val mtgoxUSD = RestProxy.fetchMtgoxUSD() 
    val mtgoxEUR = RestProxy.fetchMtgoxEUR()
    val accdata = this.getMergedAccProfileData(apdata)
    val sekdata = this.getMergedMtgoxSEKData(accdata,mtgoxSEK)
    val usddata = this.getMergedMtgoxUSDData(accdata,mtgoxUSD)
    val eurdata = this.getMergedMtgoxEURData(accdata,mtgoxEUR)
    val data = accdata merge sekdata merge usddata merge eurdata
    data
  }  
  
  /*Methods below is doing some internal calculations and json manipulations, no other external references used */
  private def getMergedServerDateTime(millis:JValue):JValue = {
    val dateTime = this.getFormatedServerDateTime(millis)
    //val dateTime = this.simpelBigIntTransform( (for {JField("btc_server_system_millis",JInt(v)) <- millis } yield v).headOption, "btc_server_dt")
    dateTime
  }
  
  private def getFormatedServerDateTime(data:JValue) :JValue = {
    val millis : Option[BigInt] = (for {JField("btc_server_system_millis",JInt(millis)) <- data } yield millis).headOption
    val date = new java.util.Date(millis.get.toLong)
    val formatter = new java.text.SimpleDateFormat("dd MMM 'at' HH:mm z") 
    val fdate = formatter.format(date)
    ("btc_server_dt" -> fdate)
  }
  
  /*
  private def getMergedKapitonData(kdata:JValue):JValue = {
    //logger.debug("BTCRestHelper::getMergedKapitonData()")
    val ask   = this.kaptionTickerAsk(kdata)
    val bid   = this.kaptionTickerBid(kdata)
    val hi    = this.kaptionTickerHi(kdata)
    val low   = this.kaptionTickerLow(kdata)
    val mave  = this.kaptionTickerMonthAverage(kdata)
    val mvol  = this.kaptionTickerMonthVolym(kdata)
    val price = this.kaptionTickerPrice(kdata)
    val vol   = this.kaptionTickerVol(kdata)
    val data = ask merge bid merge hi merge low merge mave merge mvol merge price merge vol
    data
  }
  */
  
  private def getMergedSlushPoolStatData(data:JValue):JValue = {
    //logger.debug("BTCRestHelper::getMergedSlushPoolStatData()")  
    val round      = this.simpelStringTransform((for { JField("round_started",JString(value)) <- data } yield value ).headOption,"sps_round_started")
    val stratum    = this.simpelStringTransform((for { JField("active_stratum",JString(active_stratum)) <- data } yield active_stratum ).headOption,"sps_active_stratum")
    val workers    = this.simpelStringTransform( (for { JField("active_workers",JString(value)) <- data } yield value ).headOption, "sps_active_workers") 
    val ghashshare = this.simpelStringTransform( (for { JField("ghashes_ps",JString(s)) <- data } yield s ).headOption, "sps_ghashes_ps")
{'fraction_non_alphanumeric': 0.10672914226213719, 'fraction_numerical': 0.0013015749056358194, 'mean_word_length': 4.167451244115669, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3430151', 'n_tokens_mistral': 2681, 'n_tokens_neox': 2666, 'n_words': 480}