private void setField(FootballerScoreDetailElement element, String fieldName, ScoreExplain explain)
 {
     try {
         var field = typeof(FootballerScoreDetailElement).GetProperty(fieldName);
         field.SetValue(element, explain);
     } catch (Exception e) {
         _log.Error(e);
     }
 }
    public ScoreExplain diff(ScoreExplain other)
    {
        ScoreExplain diff = new ScoreExplain();

        diff.name   = other.name;
        diff.points = points - other.points;
        diff.value  = value - other.value;
        return(diff);
    }
Esempio n. 3
0
 public void set(FootballerScoreDetailElement other)
 {
     minutes          = other.minutes;
     goals_scored     = other.goals_scored;
     bonus            = other.bonus;
     clean_sheets     = other.clean_sheets;
     assists          = other.assists;
     yellow_cards     = other.yellow_cards;
     red_cards        = other.red_cards;
     penalties_missed = other.penalties_missed;
     goals_conceded   = other.goals_conceded;
     saves            = other.saves;
     penalties_saved  = other.penalties_saved;
     own_goals        = other.own_goals;
 }
    public List <FootballerScoreDetailElement> getExplains()
    {
        var parsed = new List <FootballerScoreDetailElement>();
        FootballerScoreDetailElement parsedExplains = new FootballerScoreDetailElement();

        foreach (var singleExplain in explain)
        {
            foreach (var stat in singleExplain.stats)
            {
                var fieldName    = stat.identifier;
                var scoreExplain = new ScoreExplain();
                scoreExplain.name   = fieldName;
                scoreExplain.points = stat.points;
                scoreExplain.value  = stat.value;
                setField(parsedExplains, fieldName, scoreExplain);
            }
            parsed.Add(parsedExplains);
        }
        return(parsed);
    }
    public int calculateFootballerScore(IList <FootballerScoreDetailElement> explains)
    {
        int score  = 0;
        var fields = typeof(FootballerScoreDetailElement).GetProperties();

        foreach (var gwExplain in explains)
        {
            foreach (var field in fields)
            {
                try
                {
                    ScoreExplain explain = (ScoreExplain)field.GetValue(gwExplain);
                    score += explain.points;
                }
                catch (Exception e)
                {
                    _log.Error(e);
                }
            }
        }
        return(score);
    }