# Path: browser/models.py
# 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',)
# 
# 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)


import re,os
import config
import gzip
import time
from django.core.management.base import BaseCommand, CommandError
from browser.models import Overlap, Compare
from django.core.paginator import Paginator
from neo4j.v1 import GraphDatabase,basic_auth
				sOut.close()

			print len(sConcepts)
			print "Updating names with semmed types"
			counter=0
			for o in chunked_iterator(Overlap.objects.all()):
				if counter % 10000 == 0:
					t = time.asctime( time.localtime(time.time()) )
					print t,o.id,counter
				counter+=1
			#for o in Overlap.objects.all().iterator():
				#fibrillin||ASSOCIATED_WITH||Marfan Syndrome||4965773:Marfan Syndrome||PROCESS_OF||Sister||83749
				if o.mc_id.job_type == 'semmed_t' or o.mc_id.job_type == 'semmed':
					oSplit = o.name.split('||')
					if len(oSplit)==7:
						#print o.id
						s1,s2,s3,s4,s5,s6,s7 = o.name.split('||')
						s_type1 = s_type3 = s_type4 = s_type6 = 'n/a'
						if s1 in sConcepts:
							s_type1 = sConcepts[s1]
						if s3 in sConcepts:
							s_type3 = sConcepts[s3]
						if s4 in sConcepts:
							s_type4 = sConcepts[s4.split(':')[1]]
						if s6 in sConcepts:
							s_type6 = sConcepts[s6]
						if s1 in sConcepts or s3 in sConcepts or s6 in sConcepts:
							newName = s1+' ('+s_type1+')||'+s2+'||'+s3+' ('+s_type3+')||'\
								  +s4+' ('+s_type4+')||'+s5+'||'+s6+' ('+s_type6+')||'+s7
							#print newName

# Path: browser/models.py
# 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',)
# 
# 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)


# Path: browser/management/commands/update_overlaps.py
import re,os
import config
import gzip
import time
from django.core.management.base import BaseCommand, CommandError
from browser.models import Overlap, Compare
from django.core.paginator import Paginator
from neo4j.v1 import GraphDatabase,basic_auth

				sOut.close()

			print len(sConcepts)
			print "Updating names with semmed types"
			counter=0
			for o in chunked_iterator(Overlap.objects.all()):
				if counter % 10000 == 0:
					t = time.asctime( time.localtime(time.time()) )
					print t,o.id,counter
				counter+=1
			#for o in Overlap.objects.all().iterator():
				#fibrillin||ASSOCIATED_WITH||Marfan Syndrome||4965773:Marfan Syndrome||PROCESS_OF||Sister||83749
				if o.mc_id.job_type == 'semmed_t' or o.mc_id.job_type == 'semmed':
					oSplit = o.name.split('||')
					if len(oSplit)==7:
						#print o.id
						s1,s2,s3,s4,s5,s6,s7 = o.name.split('||')
						s_type1 = s_type3 = s_type4 = s_type6 = 'n/a'
						if s1 in sConcepts:
							s_type1 = sConcepts[s1]
						if s3 in sConcepts:
							s_type3 = sConcepts[s3]
						if s4 in sConcepts:
							s_type4 = sConcepts[s4.split(':')[1]]
						if s6 in sConcepts:
							s_type6 = sConcepts[s6]
						if s1 in sConcepts or s3 in sConcepts or s6 in sConcepts:
							newName = s1+' ('+s_type1+')||'+s2+'||'+s3+' ('+s_type3+')||'\
								  +s4+' ('+s_type4+')||'+s5+'||'+s6+' ('+s_type6+')||'+s7
							#print newName

							Overlap.objects.filter(id=o.id).update(name=newName)