# -*- coding: utf-8 -*-

import os.path
import random
from define import *
#define

def fileWrite(NBneurone,NBneuroneMoins1,N,path):
	weight=[]
	add=[]
	for i in range(NBneurone):
		weight.append(random.uniform(0.0, 2.0))
		tmp=[]
		for j in range(MulParNeurone):
			tmp.append(random.randrange(0,NBneuroneMoins1))
		add.append(tmp)
	F_weight = open(path + "poids"+str(N)+".wei","w")	
	F_AddPos = open(path + "Addresse"+str(N)+".pos","w")
	
	for i in weight : 
		F_weight.write(str(i)+"\n")
		
	for i in add :
		F_AddPos.write(str(i)+"\n")
	
	F_AddPos.close()
	F_weight.close()
	
def GenerateFile():
	F_resume = open("resume.txt","r")
	file_lines = F_resume.readlines()
	F_resume.close ()
	last_line = file_lines [ len ( file_lines ) -1]
	ID=int(last_line.split(":")[0])+1
	print ("Numero du test : " + str(ID))
	path = D_file + str(ID) + "/"
	
	os.mkdir(path)
	
	fileWrite(NBC2,NBC1,2,path)
	fileWrite(NBC3,NBC2,3,path)
	fileWrite(NBC4,NBC3,4,path)
	fileWrite(NBC5,NBC4,5,path)
	
	return int(ID)
	
def CalculPourcentage(Portefeuille,Actions,Frais):
	val = Portefeuille
	for act in Actions:
		val+=act.getValue()
	val-=(Frais*3.9)
	return (val/initPortefeuille)

def MAJQuotidient(jou,Actions):
	for act in Actions:
		act.MajQuotidient(jou)

def MAJ1min(minu,Actions):
	tab=[]
	for act in Actions:
		act.Maj1min(minu)
		tab.extend(act.getTable())
	return tab
	
