diff --git a/Makefile b/Makefile index 00a914f..6dd5393 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,11 @@ generate_over_all_reports: --method=VisitsSummary.get #overall views country wise $(SCRIPT) --date=$(START_DATE),$(END_DATE) \ - --idSite=2,4 --columns=code,nb_uniq_visitors,nb_visits \ + --idSite=2 --columns=code,nb_uniq_visitors,nb_visits \ --method=UserCountry.getCountry + $(SCRIPT) --date=$(START_DATE),$(END_DATE) \ + --idSite=4 --columns=code,nb_uniq_visitors,nb_visits \ + --method=UserCountry.getCountry #overall most visited pages $(SCRIPT) --date=$(START_DATE),$(END_DATE) \ --idSite=2,4 --columns=label,url,nb_visits,nb_hits \ @@ -137,3 +140,5 @@ generate_others_reports: all: generate_over_all_reports generate_repository_reports generate_LRT_reports generate_services_reports generate_others_reports date > $(INDEX)/last_updated.txt + wget -q -O - https://lindat.mff.cuni.cz/statistics/reload > /dev/null + diff --git a/scripts/luc/searcher.py b/scripts/luc/searcher.py index 91b7a62..2713ed5 100644 --- a/scripts/luc/searcher.py +++ b/scripts/luc/searcher.py @@ -304,6 +304,8 @@ def search_handle(self, dmy=None, period='year', site_id=None, handle=None, segm results = dict() if period == 'year': + results["total"] = {"nb_visits": 0, "nb_hits": 0} + else: results["total"] = {} for doc in docs: @@ -326,12 +328,16 @@ def search_handle(self, dmy=None, period='year', site_id=None, handle=None, segm results[year] = {} if url not in results[year]: results[year][url] = {"nb_visits": 0, "nb_hits": 0} - if url not in results["total"]: - results["total"][url] = {"nb_visits": 0, "nb_hits": 0} results[year][url]["nb_visits"] += nb_visits results[year][url]["nb_hits"] += nb_hits - results["total"][url]["nb_visits"] += nb_visits - results["total"][url]["nb_hits"] += nb_hits + + if year not in results["total"]: + results["total"][year] = {"nb_visits": 0, "nb_hits": 0} + results["total"]["nb_visits"] += nb_visits + results["total"]["nb_hits"] += nb_hits + results["total"][year]["nb_visits"] += nb_visits + results["total"][year]["nb_hits"] += nb_hits + elif period == 'month': if year not in results: results[year] = {} @@ -341,6 +347,14 @@ def search_handle(self, dmy=None, period='year', site_id=None, handle=None, segm results[year][month][url] = {"nb_visits": 0, "nb_hits": 0} results[year][month][url]["nb_visits"] += nb_visits results[year][month][url]["nb_hits"] += nb_hits + + if year not in results["total"]: + results["total"][year] = {} + if month not in results["total"][year]: + results["total"][year][month] = {"nb_visits": 0, "nb_hits": 0} + results["total"][year][month]["nb_visits"] += nb_visits + results["total"][year][month]["nb_hits"] += nb_hits + elif period == 'day': if year not in results: results[year] = {} @@ -353,7 +367,17 @@ def search_handle(self, dmy=None, period='year', site_id=None, handle=None, segm results[year][month][day][url]["nb_visits"] += nb_visits results[year][month][day][url]["nb_hits"] += nb_hits + if year not in results["total"]: + results["total"][year] = {} + if month not in results["total"][year]: + results["total"][year][month] = {} + if day not in results["total"][year][month]: + results["total"][year][month][day] = {"nb_visits": 0, "nb_hits": 0} + results["total"][year][month][day]["nb_visits"] += nb_visits + results["total"][year][month][day]["nb_hits"] += nb_hits + return results def close(self): self.directory.close() + diff --git a/scripts/search_application.py b/scripts/search_application.py index 4bbc46a..562f1c1 100644 --- a/scripts/search_application.py +++ b/scripts/search_application.py @@ -15,6 +15,13 @@ def home(): return f.read() +@app.route('/reload') +def reload(): + global s + s = searcher.Searcher(index) + return "done" + + @app.route('/views') def search_views(): dmy = request.args.get('date', None) @@ -77,13 +84,23 @@ def search_hanlde(): h = request.args.get('h') seg = request.args.get('segment', None) sid = [2, 4] + res = dict() if seg == "views": sid = 2 segment = "pageUrl=@lindat.mff.cuni.cz/repository/xmlui/handle" + res["response"] = s.search_handle(dmy=dmy, period=period, site_id=sid, handle=h, segment=segment) elif seg == "downloads": sid = 4 - res = dict() - res["response"] = s.search_handle(dmy=dmy, period=period, site_id=sid, handle=h, segment=segment) + res["response"] = s.search_handle(dmy=dmy, period=period, site_id=sid, handle=h, segment=segment) + else: + res = dict() + sid = 2 + segment = "pageUrl=@lindat.mff.cuni.cz/repository/xmlui/handle" + res["response"] = {} + res["response"]["views"] = s.search_handle(dmy=dmy, period=period, site_id=sid, handle=h, segment=segment) + sid = 4 + res["response"]["downloads"] = s.search_handle(dmy=dmy, period=period, site_id=sid, handle=h, segment=None) + return jsonify(res)