# Path: browser/models.py
# class SearchSet(models.Model):
# 	user_id = models.CharField(max_length=200)
# 	job_name = models.CharField(max_length=200)
# 	job_id = models.CharField(max_length=200)
# 	job_start = models.CharField(max_length=30)
# 	job_status = models.CharField(max_length=20)
# 	job_progress = models.IntegerField()
# 	ss_file = models.FileField(upload_to='/var/django/melodi/abstracts')
# 	ss_desc = models.CharField(max_length=5000)
# 	pTotal = models.IntegerField()
# 
# 	class Meta:
# 		unique_together = ('user_id', 'job_name',),
# 
# 	#def __str__(self):
# 	#	return "User: " + self.user_id
# 
# class SearchSetAnalysis(models.Model):
# 	ss_id = models.ForeignKey(SearchSet)
# 	job_type =  models.CharField(max_length=20)
# 	complete = models.BooleanField(default=False)
# 	year_range = models.CharField(max_length=12)
# 
# class Compare(models.Model):
# 	user_id = models.CharField(max_length=200)
# 	job_name = models.CharField(max_length=200)
# 	job_desc = models.CharField(max_length=400)
# 	job_start = models.CharField(max_length=30)
# 	job_status = models.CharField(max_length=20)
# 	job_progress = models.IntegerField()
# 	job_type = models.CharField(max_length=20)
# 	year_range = models.CharField(max_length=12)
# 	share = models.BooleanField(default=False)
# 	hash_id = models.UUIDField(db_index=True,default=uuid.uuid4, editable=False)
# 
# class Overlap(models.Model):
# 	mc_id = models.ForeignKey(Compare)
# 	name = models.CharField(max_length=500,blank=True,db_index=True)
# 	name1 = models.CharField(max_length=200,blank=True,db_index=True)
# 	name2 = models.CharField(max_length=50,blank=True,db_index=True)
# 	name3 = models.CharField(max_length=200,blank=True,db_index=True)
# 	name4 = models.CharField(max_length=50,blank=True,db_index=True)
# 	name5 = models.CharField(max_length=200,blank=True,db_index=True)
# 	mean_cp = models.FloatField()
# 	mean_odds = models.FloatField()
# 	uniq_a = models.IntegerField()
# 	uniq_b = models.IntegerField()
# 	shared = models.IntegerField()
# 	score = models.FloatField()
# 	treeLevel = models.FloatField()
# 
# 	class Meta:
# 		unique_together = ('name', 'mc_id',)


from celery import shared_task, task
from celery.task import periodic_task
from celery.schedules import crontab
from django.core.mail import send_mail
from datetime import timedelta
from random import randint
from scipy import stats
from browser.models import SearchSet,SearchSetAnalysis,Compare,Overlap
from celery.utils.log import get_task_logger
from collections import defaultdict
from retrying import retry
from django.conf import settings
from neo4j.v1 import GraphDatabase,basic_auth
import datetime
import sys,gzip,time,os,subprocess,re,json,random
import statsmodels.sandbox.stats.multicomp as sm
import logging
import zipfile
import requests
import random
import shutil
import config
					if pfDic[p1]>pfDic[p2]:
						pfVal = pfDic[p2]
					else:
						pfVal = pfDic[p1]
					#print "pfVal = "+str(pfVal)

					# calculate temmpo1 style score
					# score1 = min(bf,df)/max(bf,df)*(bf+df)
					if (uniq_a and uniq_b) > 0.0:
						score = min(uniq_a, uniq_b) / max(uniq_a, uniq_b) * (uniq_a + uniq_b)
						score = ("%4.2f" % score)
					else:
						score = 0
					# ignore cases where no uniques in one search set
					if score > 0:
						#s = Overlap(name=semDic[sKey1] + "||" + str(sKey1) + ":" + semDic[sKey2] + "||" + str(sKey2), mc_id=c,
						#			mean_cp=("%03.02e" % float(pMean)), mean_odds=("%4.2f" % float(oMean)), uniq_a=uniq_a,
						#			uniq_b=uniq_b, shared=oDicSum[i][s1_name + ":" + s2_name], score=score, treeLevel=pfVal)
						s1,s2,s3 = semDic[sKey1].split("||")
						s3,s4,s5 = semDic[sKey2].split("||")
						logger.debug(s1+' '+s2+' '+s3+' '+s4+' '+s5)
						name = s1 +' ('+semTypeDic[s1]+')||'+s2+'||'+s3+' ('+semTypeDic[s3]+')' + "||" + str(sKey1) + ":" + s3 +' ('+semTypeDic[s3]+')||'+s4+'||'+s5+' ('+semTypeDic[s5]+')' + "||" + str(sKey2)
						logger.debug(name)
						s = Overlap(name=name,
									name1=s1+' ('+semTypeDic[s1]+')',name2=s2,name3=s3+' ('+semTypeDic[s3]+')',name4=s4,name5=s5+' ('+semTypeDic[s5]+')', mc_id=c,
									mean_cp=("%03.02e" % float(pMean)), mean_odds=("%4.2f" % float(oMean)), uniq_a=uniq_a,
									uniq_b=uniq_b, shared=oDicSum[i][s1_name + ":" + s2_name], score=score, treeLevel=pfVal)
						bi.append(s)
						#s.save()
			#add in bulk

# Path: browser/models.py
# class SearchSet(models.Model):
# 	user_id = models.CharField(max_length=200)
# 	job_name = models.CharField(max_length=200)
# 	job_id = models.CharField(max_length=200)
# 	job_start = models.CharField(max_length=30)
# 	job_status = models.CharField(max_length=20)
# 	job_progress = models.IntegerField()
# 	ss_file = models.FileField(upload_to='/var/django/melodi/abstracts')
# 	ss_desc = models.CharField(max_length=5000)
# 	pTotal = models.IntegerField()
# 
# 	class Meta:
# 		unique_together = ('user_id', 'job_name',),
# 
# 	#def __str__(self):
# 	#	return "User: " + self.user_id
# 
# class SearchSetAnalysis(models.Model):
# 	ss_id = models.ForeignKey(SearchSet)
# 	job_type =  models.CharField(max_length=20)
# 	complete = models.BooleanField(default=False)
# 	year_range = models.CharField(max_length=12)
# 
# class Compare(models.Model):
# 	user_id = models.CharField(max_length=200)
# 	job_name = models.CharField(max_length=200)
# 	job_desc = models.CharField(max_length=400)
# 	job_start = models.CharField(max_length=30)
# 	job_status = models.CharField(max_length=20)
# 	job_progress = models.IntegerField()
# 	job_type = models.CharField(max_length=20)
# 	year_range = models.CharField(max_length=12)
# 	share = models.BooleanField(default=False)
# 	hash_id = models.UUIDField(db_index=True,default=uuid.uuid4, editable=False)
# 
# class Overlap(models.Model):
# 	mc_id = models.ForeignKey(Compare)
# 	name = models.CharField(max_length=500,blank=True,db_index=True)
# 	name1 = models.CharField(max_length=200,blank=True,db_index=True)
# 	name2 = models.CharField(max_length=50,blank=True,db_index=True)
# 	name3 = models.CharField(max_length=200,blank=True,db_index=True)
# 	name4 = models.CharField(max_length=50,blank=True,db_index=True)
# 	name5 = models.CharField(max_length=200,blank=True,db_index=True)
# 	mean_cp = models.FloatField()
# 	mean_odds = models.FloatField()
# 	uniq_a = models.IntegerField()
# 	uniq_b = models.IntegerField()
# 	shared = models.IntegerField()
# 	score = models.FloatField()
# 	treeLevel = models.FloatField()
# 
# 	class Meta:
# 		unique_together = ('name', 'mc_id',)


# Path: browser/tasks.py
from celery import shared_task, task
from celery.task import periodic_task
from celery.schedules import crontab
from django.core.mail import send_mail
from datetime import timedelta
from random import randint
from scipy import stats
from browser.models import SearchSet,SearchSetAnalysis,Compare,Overlap
from celery.utils.log import get_task_logger
from collections import defaultdict
from retrying import retry
from django.conf import settings
from neo4j.v1 import GraphDatabase,basic_auth
import datetime
import sys,gzip,time,os,subprocess,re,json,random
import statsmodels.sandbox.stats.multicomp as sm
import logging
import zipfile
import requests
import random
import shutil
import config

					if pfDic[p1]>pfDic[p2]:
						pfVal = pfDic[p2]
					else:
						pfVal = pfDic[p1]
					#print "pfVal = "+str(pfVal)

					# calculate temmpo1 style score
					# score1 = min(bf,df)/max(bf,df)*(bf+df)
					if (uniq_a and uniq_b) > 0.0:
						score = min(uniq_a, uniq_b) / max(uniq_a, uniq_b) * (uniq_a + uniq_b)
						score = ("%4.2f" % score)
					else:
						score = 0
					# ignore cases where no uniques in one search set
					if score > 0:
						#s = Overlap(name=semDic[sKey1] + "||" + str(sKey1) + ":" + semDic[sKey2] + "||" + str(sKey2), mc_id=c,
						#			mean_cp=("%03.02e" % float(pMean)), mean_odds=("%4.2f" % float(oMean)), uniq_a=uniq_a,
						#			uniq_b=uniq_b, shared=oDicSum[i][s1_name + ":" + s2_name], score=score, treeLevel=pfVal)
						s1,s2,s3 = semDic[sKey1].split("||")
						s3,s4,s5 = semDic[sKey2].split("||")
						logger.debug(s1+' '+s2+' '+s3+' '+s4+' '+s5)
						name = s1 +' ('+semTypeDic[s1]+')||'+s2+'||'+s3+' ('+semTypeDic[s3]+')' + "||" + str(sKey1) + ":" + s3 +' ('+semTypeDic[s3]+')||'+s4+'||'+s5+' ('+semTypeDic[s5]+')' + "||" + str(sKey2)
						logger.debug(name)
						s = Overlap(name=name,
									name1=s1+' ('+semTypeDic[s1]+')',name2=s2,name3=s3+' ('+semTypeDic[s3]+')',name4=s4,name5=s5+' ('+semTypeDic[s5]+')', mc_id=c,
									mean_cp=("%03.02e" % float(pMean)), mean_odds=("%4.2f" % float(oMean)), uniq_a=uniq_a,
									uniq_b=uniq_b, shared=oDicSum[i][s1_name + ":" + s2_name], score=score, treeLevel=pfVal)
						bi.append(s)
						#s.save()
			#add in bulk

			Overlap.objects.bulk_create(bi,batch_size=1000)