<commit_before>﻿using Newtonsoft.Json.Linq;
using System;

namespace MultiMiner.Coinchoose.Api
{
    public class CoinInformation
    {
        public string Symbol { get; set; }
        public string Name { get; set; }
        public string Algorithm { get; set; }
        public int CurrentBlocks { get; set; }
        public double Difficulty { get; set; }
        public double Reward { get; set; }
        public double MinimumBlockTime { get; set; }
        public Int64 NetworkHashRate { get; set; }
        public double Price { get; set; }
        public string Exchange { get; set; }
        public double Profitability { get; set; }
        public double AdjustedProfitability { get; set; }
        public double AverageProfitability { get; set; }
        public double AverageHashRate { get; set; }

        public void PopulateFromJson(JToken jToken)
        {
            Symbol = jToken.Value<string>("symbol");
            Name = jToken.Value<string>("name");
            Algorithm = jToken.Value<string>("algo");
            if (jToken["currentBlocks"] != null) //potentially null in practice
                CurrentBlocks = jToken.Value<int>("currentBlocks");
            Difficulty = jToken.Value<double>("difficulty");
            Reward = jToken.Value<double>("reward");
            MinimumBlockTime = jToken.Value<double>("minBlockTime");
            NetworkHashRate = jToken.Value<Int64>("networkhashrate");
            Price = jToken.Value<double>("price");
            Exchange = jToken.Value<string>("exchange");
            Profitability = jToken.Value<double>("ratio");
            AdjustedProfitability = jToken.Value<double>("adjustedratio");
            AverageProfitability = jToken.Value<double>("avgProfit");
            AverageHashRate = jToken.Value<double>("avgHash");<commit_msg>Another go at handling cast exceptions parsing CoinChoose JSON<commit_after>﻿using Newtonsoft.Json.Linq;
using System;

namespace MultiMiner.Coinchoose.Api
{
    public class CoinInformation
    {
        public string Symbol { get; set; }
        public string Name { get; set; }
        public string Algorithm { get; set; }
        public int CurrentBlocks { get; set; }
        public double Difficulty { get; set; }
        public double Reward { get; set; }
        public double MinimumBlockTime { get; set; }
        public Int64 NetworkHashRate { get; set; }
        public double Price { get; set; }
        public string Exchange { get; set; }
        public double Profitability { get; set; }
        public double AdjustedProfitability { get; set; }
        public double AverageProfitability { get; set; }
        public double AverageHashRate { get; set; }

        public void PopulateFromJson(JToken jToken)
        {
            Symbol = jToken.Value<string>("symbol");
            Name = jToken.Value<string>("name");
            Algorithm = jToken.Value<string>("algo");

            try
            {
                CurrentBlocks = jToken.Value<int>("currentBlocks");
            }
            catch (InvalidCastException)
            {
                //handle System.InvalidCastException: Null object cannot be converted to a value type.
                //tried this but didn't work: if (jToken["currentBlocks"] != null)
                CurrentBlocks = 0;
            }
            
            Difficulty = jToken.Value<double>("difficulty");
            Reward = jToken.Value<double>("reward");
            MinimumBlockTime = jToken.Value<double>("minBlockTime");
            NetworkHashRate = jToken.Value<Int64>("networkhashrate");
            Price = jToken.Value<double>("price");
            Exchange = jToken.Value<string>("exchange");
            Profitability = jToken.Value<double>("ratio");
            AdjustedProfitability = jToken.Value<double>("adjustedratio");
            AverageProfitability = jToken.Value<double>("avgProfit");
            AverageHashRate = jToken.Value<double>("avgHash");
{'fraction_non_alphanumeric': 0.10858010630220197, 'fraction_numerical': 0.002277904328018223, 'mean_word_length': 2.3864610111396742, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5618738', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1030, 'n_words': 261}