private async Task <int?> GetScore(string title)
        {
            var scores = (Dictionary <string, int?>)HttpRuntime.Cache.Get("scores");
            var score  = ScoreCache.GetScore(title);

            if (score == null)
            {
                // Get score
                using (var client = new HttpClient())
                {
                    var response = await client.GetAsync("http://bechdeltest.com/api/v1/getMoviesByTitle?title=" + HttpUtility.UrlEncode(title));

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new FileNotFoundException(string.Format("Could not find Bechdel score for '{0}'.", title));
                    }

                    var rawJson = await response.Content.ReadAsStringAsync();

                    JArray array = JArray.Parse(rawJson);
                    if (array.Count != 0)
                    {
                        score = array.First.Value <int>("rating");
                    }
                }

                // Put in cache
                ScoreCache.UpsertScore(title, score);
            }

            return((int?)score);
        }
        /// <summary>
        /// Gets the cached score for this senone based upon the given feature.
        /// If the score was not cached, it is calculated using {@link #calculateScore},
        /// cached, and then returned.
        /// </summary>
        public virtual float GetScore(IData feature)
        {
            var cached = _scoreCache;

            if (feature != cached.Feature)
            {
                cached      = new ScoreCache(feature, CalculateScore(feature));
                _scoreCache = cached;
            }
            return(cached.Score);
        }
示例#3
0
        private void btnIcon_Click(object sender, EventArgs e)
        {
            if (tbxLeague.Text.Length > 0)
            {
                if (pictureBox1.Image != null)
                {
                    pictureBox1.Image.Dispose();
                    pictureBox1.Image = null;
                }

                string     url   = Tools.ParseUrl(GetUrl(), m_center.Parameters);
                ScoreCache cache = new ScoreCache(0);
                string     home  = cache.GetScore(url, "", false);

                string emblemUrl = WorldFootballScoreParser.GetEmblemUrl(home);
                if (String.IsNullOrEmpty(emblemUrl))
                {
                    return;
                }

                string tmpfile = Path.GetTempFileName();
                File.Delete(tmpfile);
                tmpfile += ".png";
                Bitmap bmp = null;
                try
                {
                    cache.GetImage(emblemUrl, tmpfile);
                    bmp = new Bitmap(tmpfile);
                    Image icon = Tools.FixedBitmapSize(bmp, 48, 48, Color.White);
                    pictureBox1.Image = icon;

                    string relpath = Path.Combine("Football", GetFullName());
                    string path    = Config.GetSubFolder(Config.Dir.Thumbs, "ScoreCenter");
                    path = Path.Combine(path, relpath + ".png");
                    icon.Save(path, ImageFormat.Png);
                    NotifySetIcon(relpath);
                }
                finally
                {
                    cache = null;
                    if (bmp != null)
                    {
                        bmp.Dispose();
                    }
                    File.Delete(tmpfile);
                }
            }
        }
示例#4
0
        public int PlayCachedGame(int q)
        {
            int realQ = MapQuality(q);

            if (!cache.ContainsKey(q))
            {
                //Copy the samples to the bin/Debug directory
                cache[q] = new ScoreCache
                {
                    Data  = File.ReadAllLines($"samples-d{realQ}.dat").Select(int.Parse).ToArray(),
                    Index = 0
                };
            }
            var data = cache[q];

            return(data.Data[rng.Next(data.Data.Length)]);
        }
示例#5
0
 /// <summary>
 /// Default Constructor.
 /// </summary>
 public ScoreParser(int lifeTime)
 {
     m_cache = new ScoreCache(lifeTime);
 }