#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import os
import json
#===============================================================================
def getMinMax(clase):

	polylist = []
	for item in os.listdir("."):
		if os.path.isdir(item):
			print(item)
			with open(os.getcwd()+"/"+item+"/scl_data.json") as json_file:
				dataSCL = json.load(json_file)
				
			with open(os.getcwd()+"/"+item+"/findProducts.json") as json_file:
				dataWKT = json.load(json_file)
			wkt = dataWKT["wkt"]
			
			values = []
			for k, v in dataSCL.items():
				values.append(v[clase])
			minval = min(values)
			maxval = max(values)
			polylist.append({"wkt":wkt, "min":minval, "max":maxval})

	
	with open('minmax_'+clase+'.json', 'w') as outfile:
		json.dump(polylist, outfile)
#===============================================================================
def main(argv):

	if len(sys.argv) != 2:
		print ("Usage text")
	else:
		getMinMax(argv[1])


if __name__ == "__main__":
	main(sys.argv)
