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

from define import *
from statistics import mean
import math

def mult(Addresse,Neuronne, poids):

	
	res = mean([Neuronne[Addresse[0]] , \
	Neuronne[Addresse[1]] , \
	Neuronne[Addresse[2]] , \
	Neuronne[Addresse[3]] , \
	Neuronne[Addresse[4]] , \
	Neuronne[Addresse[5]] , \
	Neuronne[Addresse[6]] , \
	Neuronne[Addresse[7]] , \
	Neuronne[Addresse[8]] , \
	Neuronne[Addresse[9]] , \
	Neuronne[Addresse[10]] , \
	Neuronne[Addresse[11]] , \
	Neuronne[Addresse[12]] , \
	Neuronne[Addresse[13]] , \
	Neuronne[Addresse[14]] , \
	Neuronne[Addresse[15]] , \
	Neuronne[Addresse[16]] , \
	Neuronne[Addresse[17]] , \
	Neuronne[Addresse[18]] , \
	Neuronne[Addresse[19]] , \
	Neuronne[Addresse[20]] , \
	Neuronne[Addresse[21]] , \
	Neuronne[Addresse[22]] , \
	Neuronne[Addresse[23]] , \
	Neuronne[Addresse[24]] , \
	Neuronne[Addresse[25]] , \
	Neuronne[Addresse[26]] , \
	Neuronne[Addresse[27]] , \
	Neuronne[Addresse[28]] , \
	Neuronne[Addresse[29]] , \
	Neuronne[Addresse[30]] ])
	
	res = res * poids
	
	
	res = 1.7159*math.atan( 0.66666667*(res))
	#print (res)
	return res
	

# Fonction d'initialisation du reseau de neuronne
class RDN():
	def __init__(self,ID):
		
		self.ID = ID
		
		self.C1 = [0]*NBC1		
		self.C2 = [0]*NBC2
		self.C3 = [0]*NBC3
		self.C4 = [0]*NBC4
		self.C5 = [0]*NBC5
		
		path = D_file + str(self.ID) + "/"
		
		#changer les addresse des fichier des poids avec l'ID
		F_add2=open(path + "Addresse2.pos","r")
		F_add3=open(path + "Addresse3.pos","r")
		F_add4=open(path + "Addresse4.pos","r")
		F_add5=open(path + "Addresse5.pos","r")
		
		F_Poid2=open(path + "poids2.wei","r")
		F_Poid3=open(path + "poids3.wei","r")
		F_Poid4=open(path + "poids4.wei","r")
		F_Poid5=open(path + "poids5.wei","r")
		
		self.add2 = []
		self.add3 = []
		self.add4 = []
		self.add5 = []
		
		self.poid2 = []
		self.poid3 = []
		self.poid4 = []
		self.poid5 = []		
		
		for i in F_add2:
			data = i.strip('][\n').split(', ')
			tmp=[]
			for j in data:
				tmp.append(int(j))
			self.add2.append(tmp)
			
		for i in F_add3:
			data = i.strip('][\n').split(', ')
			tmp=[]
			for j in data:
				tmp.append(int(j))
			self.add3.append(tmp)

		for i in F_add4:
			data = i.strip('][\n').split(', ')
			tmp=[]
			for j in data:
				tmp.append(int(j))
			self.add4.append(tmp)

		for i in F_add5:
			data = i.strip('][\n').split(', ')
			tmp=[]
			for j in data:
				tmp.append(int(j))
			self.add5.append(tmp)
			
		for i in F_Poid2:
			self.poid2.append(float(i))
		for i in F_Poid3:
			self.poid3.append(float(i))		
		for i in F_Poid4:
			self.poid4.append(float(i))
		for i in F_Poid5:
			self.poid5.append(float(i))
		
	def MiseAJourC1(self,tab):
		self.C1 = tab
		
		
	def tour(self):

		for i in range(len(self.C2)):
			self.C2[i]=mult(self.add2[i],self.C1,self.poid2[i])
		
		for i in range(len(self.C3)):
			self.C3[i]=mult(self.add3[i],self.C2,self.poid3[i])
			
		for i in range(len(self.C4)):
			self.C4[i]=mult(self.add4[i],self.C3,self.poid4[i])
			
		for i in range(len(self.C5)):
			self.C5[i]=mult(self.add5[i],self.C4,self.poid5[i])
		return self.C5
