Exemple #1
0
def mep_raw(request, mep_id):
    mep_ = MEP.get(mep_id)
    jsonstr = simplejson.dumps(dict(mep_), indent=4, use_decimal=True)
    context = {
        'mep_id': mep_id,
        'mep': mep_,
        'jsonstr': jsonstr,
    }
    return direct_to_template(request, 'meps/mep_raw.html', context)
Exemple #2
0
 def test_trophies_retrieval_from_mep(self):
     """
     Test that meps' CouchDB model can retrieve associated Django trophies.
     """
     # Initialization
     a_mep = MEP.get('AlainLipietz')
     manual_trophy = ManualTrophy.objects.create(label="A manual trophy")
     auto_trophy = AutoTrophy.objects.create(label="An auto trophy")
     self.failUnlessEqual(a_mep.trophies, [])
     
     # Let's create a reward and attribute it to verify CouchDB's update
     reward = Reward.objects.create(mep_wikiname=a_mep._id, trophy=manual_trophy, reason="test")
     a_mep = MEP.get('AlainLipietz')
     self.failUnlessEqual(repr(a_mep.trophies), "[<ManualTrophy: A manual trophy>]")
     
     # OK, now we verify that deletion is triggered to CouchDB
     reward.delete()
     a_mep = MEP.get('AlainLipietz')
     self.failUnlessEqual(a_mep.trophies, [])
Exemple #3
0
 def test_trophies_attribution(self):
     """
     Test that trophies' models can interact with CouchDB.
     """
     # Initialization
     a_mep = MEP.get('AlainLipietz')
     manual_trophy = ManualTrophy.objects.create(label="A manual trophy")
     auto_trophy = AutoTrophy.objects.create(label="An auto trophy")
     self.failUnlessEqual(a_mep.trophies_ids, [])
     
     # Let's create a reward and attribute it to verify CouchDB's update
     reward = Reward.objects.create(mep_wikiname=a_mep._id, trophy=manual_trophy, reason="test")
     a_mep = MEP.get('AlainLipietz')
     self.failUnlessEqual(a_mep.trophies_ids, [1])
     
     # OK, now we verify that deletion is triggered to CouchDB
     reward.delete()
     a_mep = MEP.get('AlainLipietz')
     self.failUnlessEqual(a_mep.trophies_ids, [])
Exemple #4
0
def mep(request, mep_id):
    mep_ = MEP.get(mep_id)
    mep_["achievements"] = autoTrophies(mep_)
    positions = Position.objects.filter(mep_id=mep_id)
    score_list = mep_.scores
    for score in score_list:
        score["color"] = score_to_color(int(score["value"]))
    score_list.sort(key=lambda k: datetime.strptime(k["date"], "%d/%m/%Y"))
    scores = [s["value"] for s in mep_.scores]

    if score_list:
        try:
            import numpy
            import matplotlib

            matplotlib.use("Agg")
            from matplotlib import pyplot

            pyplot.plot(scores, "bo")
            a, b = numpy.polyfit(range(len(scores)), [int(x) for x in scores], 1)
            pyplot.plot([a * int(x) + b for x in range(len(scores))])
            pyplot.legend(("Scores", "Mediane"), "best", shadow=True)
            pyplot.plot(scores)
            pyplot.axis([0, len(scores) - 1, 0, 102])
            pyplot.title("%s - Votes notes evolution over time" % (mep_.infos["name"]["full"]))
            pyplot.xticks(range(len(scores)), [k["date"] for k in score_list])
            pyplot.xlabel("Votes dates")
            pyplot.ylabel("Scores on votes")
            pyplot.savefig(
                realpath("./memopol2/%simg/trends/meps/%s-scores.png" % (settings.MEDIA_URL, mep_id)), format="png"
            )
            pyplot.clf()
        except ImportError:
            pass

    context = {
        "mep_id": mep_id,
        "mep": mep_,
        "positions": positions,
        "visible_count": len([x for x in positions if x.visible]),
        "average": sum(scores) / len(scores) if len(scores) > 0 else "",
        "score_list": score_list,
    }
    return direct_to_template(request, "meps/mep.html", context)
Exemple #5
0
def mep(request, mep_id):
    mep_ = MEP.get(mep_id)
    positions = Position.objects.filter(mep_id=mep_id)
    score_list = mep_.scores
    for score in score_list:
        score['color'] = score_to_color(int(score['value']))
    score_list.sort(key = lambda k : datetime.strptime(k['date'], "%d/%m/%Y"))
    scores = [s['value'] for s in mep_.scores]

    if score_list:
        try:
            import numpy
            import matplotlib
            matplotlib.use("Agg")
            from matplotlib import pyplot

            pyplot.plot(scores, 'bo')
            a, b = numpy.polyfit(range(len(scores)), [int(x) for x in scores], 1)
            pyplot.plot([a*int(x) + b for x in range(len(scores))])
            pyplot.legend(('Scores', 'Mediane'), 'best', shadow=True)
            pyplot.plot(scores)
            pyplot.axis([0, len(scores) - 1, 0, 102])
            pyplot.title("%s - Votes notes evolution over time" % (mep_.infos['name']['full']))
            pyplot.xticks(range(len(scores)), [k['date'] for k in score_list])
            pyplot.xlabel("Votes dates")
            pyplot.ylabel("Scores on votes")
            pyplot.savefig(realpath(".%simg/trends/meps/%s-scores.png" % (settings.MEDIA_URL, mep_id)), format="png")
            pyplot.clf()
        except ImportError:
            pass

    context = {
        'mep_id': mep_id,
        'mep': mep_,
        'positions': positions,
        'visible_count': len([x for x in positions if x.visible]),
        'average': sum(scores)/len(scores) if len(scores) > 0 else "",
        'score_list' : score_list,
    }
    return direct_to_template(request, 'meps/mep.html', context)
Exemple #6
0
 def mep(self):
     return MEP.get(self.mep_wikiname)
Exemple #7
0
 def setUp(self):
     # Delete all trophies for the test user
     a_mep = MEP.get('AlainLipietz')
     a_mep.trophies_ids = []
     a_mep.save()
Exemple #8
0
def mep_structure(request, mep_id):
    mep_ = MEP.get(mep_id)
    jsonstr = simplejson.dumps(dict(mep_), indent=4, use_decimal=True)
    context = {"mep_id": mep_id, "mep": mep_, "jsonstr": jsonstr}
    return direct_to_template(request, "meps/mep_structure.html", context)
Exemple #9
0
def mep_json(request, mep_id):
    mep_ = MEP.get(mep_id)
    jsonstr = simplejson.dumps(dict(mep_), indent=4, use_decimal=True)
    return HttpResponse(jsonstr, content_type="application/json")
Exemple #10
0
def mep_json(request, mep_id):
    mep_ = MEP.get(mep_id)
    jsonstr = simplejson.dumps(dict(mep_), indent=4, use_decimal=True)
    return HttpResponse(jsonstr)