import argparse
import os
from pprint import pprint
import sys
from collections import defaultdict

import sys

from postprocess import processdata
from utility import utility

parser = argparse.ArgumentParser(description="Generaets a heatmap based on geo coordinates")
parser.add_argument("--monthsFolder", "-m", default="/a/akrausetud/months", type=str,
                    help="the folder in which the months directory are residing")
parser.add_argument("--ignoreLock", "-i", help="Ignore locked file and execute anyways", action="store_true")
parser.add_argument("month", type=str, help="the month which we're interested in")

if (len(sys.argv[1:]) == 0):
    parser.print_help()
    parser.exit()

args = parser.parse_args()

if os.path.isfile(utility.addMissingSlash(args.monthsFolder) + utility.addMissingSlash(args.month) + "locked") and not args.ignoreLock:
    print "ERROR: The month " + args.month + " is being edited at the moment. Use -i if you want to force the execution of this script."
    sys.exit()


class GeoHeatmapHandler:
    toolCounter = defaultdict(int)

    def handle(self, sparqlQuery, processed):
        if (processed['#Valid'] == 'VALID' or processed['#Valid'] == '1'):
            if(processed['#Coordinates'] is not ''):
                pprint(processed['#Coordinates'])
            self.toolCounter[processed['#ToolName']] += 1

    def __str__(self):
        return pprint.pformat(sorted(self.toolCounter.iteritems(), key=lambda x: x[1], reverse=True))


handler = GeoHeatmapHandler()

processdata.processMonth(handler, args.month, args.monthsFolder)

#print handler

@@ -1020,31 +1020,43 @@
 %0A%0A%0Aclass Geo
-Heatmap
+CoordinateCollector
 Handler:%0A   
@@ -1060,37 +1060,26 @@
     
-toolCounter = defaultdict(int
+coordinates = set(
 )%0A%0A 
@@ -1267,22 +1267,36 @@
         
-pprint
+self.coordinates.add
 (process
@@ -1331,202 +1331,297 @@
     
+    pprint(
 self.
-toolCounter%5Bprocessed%5B'#ToolName'%5D%5D += 1%0A%0A    def __str__(self):%0A        return pprint.pformat(sorted(
+coordinates)%0A    %0A    def saveSetToJson(self):%0A        with open(geoCoordinates.tsv, 'w') as geoCoordinatesFile:%0A            for coordinate in 
 self.
-toolCounter.iteritems(), key=lambda x: x%5B1%5D, reverse=True))%0A%0A%0Ahandler = GeoHeatmap
+coordinates:%0A                geoCoordinatesFile.write(coordinate.replace(%22 %22, %22%5Ct%22) + %22%5Cn%22)%0A%0Ahandler = GeoCoordinateCollector
 Hand
@@ -1650,13 +1650,11 @@
 cess
-Month
+Day
 (han
@@ -1658,16 +1658,20 @@
 handler,
+ 19,
  args.mo
@@ -1699,19 +1699,29 @@
 r)%0A%0A
-#print 
 handler
+.saveSetToJson()%0A
 %0A

implement get data