def Program_6(self):
        print "Welcome to Program 6..."
        print "Starting..."

        #We read the data from the file
        reader = Reader()
        self.allData = reader.read()

        try:
            #  We set and parse the data to the respective variables
            P = float(self.allData[0])
            Dof = float(self.allData[1])
            num_seg = float(self.allData[2])
            Leng = num_seg

            print "\nP: ", P
            print "Dof: ", Dof
            print "Num Seg: ", num_seg

            #  We set an initial value of X: We choose 4 to reduce the number of operations performed by the program
            X = 4.0

            #  We perform the Calculation of X with the given data
            Ops = Operations()
            self.Result = Ops.Calculation_X(P, X, Dof, num_seg, Leng)

            print "\nResult X: ", round(self.Result, 5), "\n"

        except ValueError as e:
            print "\nError: ", e, "\nData is incorrect: Check and correct the .txt file.\n"
    def Program_Personal_Data(self):
        read = Reader()
        self.data = read.read()
        array_1 = []
        array_2 = []

        for x in range(4):
            array_1.append(self.data[x])

        for y in range(4, 8):
            array_2.append(self.data[y])

        X_Column = LinkedList()
        Y_Column = LinkedList()

        try:
            for x in array_1:
                X_Column.addNode(float(x))

            for y in array_2:
                Y_Column.addNode(float(y))

            xK = 379.11
            n = 4.0

            self.Program_7(X_Column, Y_Column, xK, n)

        except ValueError as e:
            print "\nError: ", e, "\nData is incorrect: Check and correct the .txt file.\n"
    def Program_Default_Data(self):
        read = Reader()
        #  We read the data from the Test file(s)
        self.data = read.read()
        array_1 = []
        array_2 = []

        #  We assign them to an array, to diferentiate them
        for x in range(10):
            array_1.append(self.data[x])

        for y in range(10, 20):
            array_2.append(self.data[y])

        X_Column = LinkedList()
        Y_Column = LinkedList()

        try:
            #  We create the Linked List with the given data
            for x in array_1:
                X_Column.addNode(float(x))

            for y in array_2:
                Y_Column.addNode(float(y))

            xK = 386.0
            n = 10.0

            self.Program_7(X_Column, Y_Column, xK, n)

        except ValueError as e:
            print "\nError: ", e, "\nData is incorrect: Check and correct the .txt file.\n"
Esempio n. 4
0
	def Program4(self):
		print "Welcome to the Program 4..."
		print "Starting..."

		#  MUST input a working value: 1 or 2
		mode = raw_input("Which test is it going to be? \n1 for LOC_Mode Test \n2 for the Regular Mode Test: \n")

		read = Reader()
		self.allData = read.read()

		#  1 will set of the mode for the Test 1
		if mode == "1":
			self.LOC_Mode(self.allData)
		#  2 will set up the mode for the Test 2
		elif mode == "2":
			self.Other_Mode(self.allData)
		#  Anything else will be discarded
		else:
			print "Wrong mode. Terminating now. Bye!"
	def Program_5(self):
		print "Welcome to Program 5..."
		print "Starting..."

		#  We read the data from the file
		read = Reader()
		self.allData = read.read()

		#  Set the data to the needed variables
		x = float(self.allData[0])
		dof = float(self.allData[1])
		num_seg = float(self.allData[2])
		length_seg = num_seg

		print "\nX: ", x
		print "Dof: ", dof

		#  The Error margin for comparison
		E = 0.00001

		#  Object with which we will use to calculate the integration
		integration = Integration_And_tDistribution()

		#  An infinite loop, set to calculate the integration until it reaches the condition we are looking for
		while(True):
			self.Simpson_1 = integration.Simpson(x, num_seg, dof, length_seg)
			print "\nSimpson 1: SUM of P: ", self.Simpson_1
			self.Simpson_2 = integration.Simpson(x, num_seg+10, dof, length_seg)
			print "\nSimpson 2: SUM of P: ", self.Simpson_2

			#  Are we over the Error Margin or below?
			if((self.Simpson_1 - self.Simpson_2) > E):
				num_seg = num_seg + 10
				print "\nIntegration 1 - Integration 2 = ", (self.Simpson_1 - self.Simpson_2), ". \nIs not less than E. Iterate again."
			elif((self.Simpson_1 - self.Simpson_2) < E):
				print "\nIntegration 1 - Integration 2 = ", (self.Simpson_1 - self.Simpson_2), ". \nIs less than E. Success!"
				break

		#  If we are below, we print the final result
		print "\nResult P: ", round(self.Simpson_2, 5), "\n"
Esempio n. 6
0
    def Program_8(self):
        #  Objects from the Classes we're going to use
        reader = Reader()
        Gauss = Multiple_Regression_And_Equations()
        Reg_Corr = Regression_Correlation()
        Stat_Ops = Statistics_Ops()

        print "Welcome to Program 8..."
        print "Starting..."

        reader = Reader()
        self.allData = reader.read()

        #  We set up the input data
        Wk = float(raw_input("LOC of Added Code (W): "))
        Xk = float(raw_input("LOC of Reused Code (X): "))
        Yk = float(raw_input("LOC of Mod Code (Y): "))

        array_W = []
        array_X = []
        array_Y = []
        array_Z = []

        #  We manage the data from the file
        for w in range(6):
            array_W.append(float(self.allData[w]))

        for x in range(6, 12):
            array_X.append(float(self.allData[x]))

        for y in range(12, 18):
            array_Y.append(float(self.allData[y]))

        for z in range(18, 24):
            array_Z.append(float(self.allData[z]))

        #  We calculate the the Sum of each Column...
        self.Total_W = Reg_Corr.Total_Sum(array_W)
        self.Total_X = Reg_Corr.Total_Sum(array_X)
        self.Total_Y = Reg_Corr.Total_Sum(array_Y)

        #  So we can calculate the Average
        self.Avg_W = Stat_Ops.mean(self.Total_W, len(array_W))
        self.Avg_X = Stat_Ops.mean(self.Total_X, len(array_X))
        self.Avg_Y = Stat_Ops.mean(self.Total_Y, len(array_Y))

        #  Then we set up the equations for the Gauss method
        self.Equation_1 = Gauss.Equation_1(array_W, array_X, array_Y, array_Z)
        self.Equation_2 = Gauss.Equation_2(array_W, array_X, array_Y, array_Z)
        self.Equation_3 = Gauss.Equation_3(array_W, array_X, array_Y, array_Z)
        self.Equation_4 = Gauss.Equation_4(array_W, array_X, array_Y, array_Z)

        #  We calculate the Beta's with the Gauss Regression Method, and calculate the remaining variables
        self.B0, self.B1, self.B2, self.B3 = Gauss.Guass_Method(
            self.Equation_1, self.Equation_2, self.Equation_3, self.Equation_4)
        self.Range = Gauss.Range(array_W, array_X, array_Y, array_Z, self.B0,
                                 self.B1, self.B2, self.B3, Wk, self.Avg_W, Xk,
                                 self.Avg_X, Yk, self.Avg_Y)
        Zk = self.B0 + Wk * self.B1 + Xk * self.B2 + Yk * self.B3
        UPI = Zk + self.Range
        LPI = Zk - self.Range

        #  Finally, we print the results
        print "\nBETA 0: ", round(self.B0, 5)
        print "BETA 1: ", round(self.B1, 5)
        print "BETA 2: ", round(self.B2, 5)
        print "BETA 3: ", round(self.B3, 5)
        print "Projected Hours: ", round(Zk, 2)
        print "UPI: ", round(UPI, 2)
        print "LPI: ", round(LPI, 2)
Esempio n. 7
0
	def Program3(self):
	#  For a better understandig, check the table of contents.
		print "Starting Program 3..."
		print "Getting ready to read the file of the Test..."
		
		#  We create objects from the needed Classes
		Operations = Regression_Correlation()
		Stat_Operations = Statistics_Ops()
		read = Reader()

		#  We read the data from the Test file(s)
		self.data = read.read()
		array_1 = []
		array_2 = []

		#  We assign them to an array, to diferentiate them
		for x in range(10):
			array_1.append(self.data[x])

		for y in range(10, 20):
			array_2.append(self.data[y])

		#  Objects from Linked List Class
		X_Column = LinkedList()
		Y_Column = LinkedList()

		#  We create the Linked List with the given data
		for x in array_1:
			X_Column.addNode(float(x))

		for y in array_2:
			Y_Column.addNode(float(y))

		"""
		The next sections are code blocs to obtain the respective
		parameters to get the data asked in the Program 3 document.
		E X, SUM X, AVG X, SUM X2, AVG X2.
		So we do it for the section of Y.
		"""
		SumX_Column = X_Column.get_total_sum()
		nX_Column = X_Column.total_elm
		elementsX_Column = X_Column.return_elements()
		self.Avg_X = Stat_Operations.mean(SumX_Column, nX_Column)
		print "Column X: ", elementsX_Column

		elementsX_Square_Column = []
		for x in elementsX_Column:
			square = x*x
			elementsX_Square_Column.append(square)

		self.SumX_Square_Column = Operations.Total_Sum(elementsX_Square_Column)
		self.Avg_X_Square_Column = Stat_Operations.mean(self.SumX_Square_Column, float(len(elementsX_Square_Column)))

		#  Section Y. Same data as the previous code block
		SumY_Column = Y_Column.get_total_sum()
		nY_Column = Y_Column.total_elm
		elementsY_Column = Y_Column.return_elements()
		self.Avg_Y = Stat_Operations.mean(SumY_Column, nY_Column)
		print "Column Y: ", elementsY_Column

		elementsY_Square_Column = []
		for y in elementsY_Column:
			square = y*y
			elementsY_Square_Column.append(square)

		self.SumY_Square_Column = Operations.Total_Sum(elementsY_Square_Column)
		self.Avg_Y_Square_Column = Stat_Operations.mean(self.SumY_Square_Column, float(len(elementsY_Square_Column)))

		#  We obtain the XY data
		X_per_Y = []
		for value in range(10):
			xy = elementsX_Column[value] * elementsY_Column[value]
			X_per_Y.append(xy)
			xy = 0.0
		self.SumXY = Operations.Total_Sum(X_per_Y)


		#  We obtain the final data: Beta 1, Beta 0, r x,y, r2 (Squared) and the Linear Regression yK
		self.Beta_1 = Operations.Regression_Beta_1(self.SumXY, self.Avg_X, self.Avg_Y, self.SumX_Square_Column, 10.0, self.Avg_X_Square_Column)
		self.rxy = Operations.Correlation_rxy(self.SumXY, SumX_Column, SumY_Column, self.SumX_Square_Column, self.SumY_Square_Column, 10.0)
		R2 = self.rxy * self.rxy
		self.Beta_0 = Operations.Regression_Beta_0(self.Avg_Y, self.Beta_1, self.Avg_X)
		self.YK = Operations.Yk(self.Beta_0, self.Beta_1, 386.0)

		#  Finally, we print the results
		print "\nRESULTS:"
		print "\nBeta0: ", round(self.Beta_0, 4)
		print "Beta1: ", round(self.Beta_1, 4)
		print "r x,y: ", round(self.rxy, 4)
		print "r2: ", round(R2, 4)
		print "yk: ", round(self.YK, 4)
		print ""
    def LOC(self):
        """
		LOC Method: Here lies all the operations to calculate the 
		number of lines of code, corresponding with the Program 2
		"""
        "\nWelcome. Starting LOC Program..."

        #  First, we declare the object from Class Reader
        reader = Reader()
        #  We obtain the full content of the file we read
        self.file_content = reader.read()

        #  With the content of the file, we can know the Total No. Lines of Code
        total_lines_of_code = len(self.file_content)

        #  We will use this variable to count the Classes
        Class_counter = 0
        #  And this array to save the Position where each Class is located
        array_of_Classes = []
        """
		These operations serve to save the location where each Class start.
		An If condition is used to exclude itself when counting the Classes,
		since a string 'Class' resides within the If.
		"""
        for x in xrange(0, len(self.file_content)):
            if "class" in self.file_content[
                    x] and "if" not in self.file_content[x]:
                Class_counter += 1
                array_of_Classes.append(x)
        """
		An array of Methods is used to save the amount of methods within a Class.
		We use an array, to map each Method with its corresponding Class.
		A counter is used to determine how many Methods each Class possess.
		"""
        array_Def_in_Class = []
        Def_counter = 0
        for x in xrange(0, len(array_of_Classes) - 1):
            for y in xrange(array_of_Classes[x], array_of_Classes[x + 1]):
                if "def" in self.file_content[
                        y] and "if" not in self.file_content[y]:
                    Def_counter += 1

            array_Def_in_Class.append(Def_counter)
            Def_counter = 0
        """
		This specific operation is to calculate the same as above, just for the last Class
		of each program. This was taken in consideration becuase of the logic implemented for
		program, because of an Index Out of Range exception.
		"""
        for z in xrange(array_of_Classes[(len(array_of_Classes) - 1)],
                        len(self.file_content)):
            if "def" in self.file_content[z] and "if" not in self.file_content[
                    z]:
                Def_counter += 1

        array_Def_in_Class.append(Def_counter)
        Def_counter = 0
        """
		The next operations serve to calculate the lines of code per Class.
		- The first case is only for programs with one Class within, since
		they are taken with differently logic.
		- The second case is for every other case.
		They also take in consideration a condition for the last 4 lines
		of code in the program, since they will always be the same to run each
		program, and to be reusable for other programs. 
		"""
        array_lines_in_Class = []
        counter_lines_in_Class = 0

        if len(array_of_Classes) == 1:
            for c in xrange(array_of_Classes[0], len(self.file_content)):
                counter_lines_in_Class += 1
                if (len(self.file_content) - c) <= 4:
                    counter_lines_in_Class -= 1
        else:
            for a in xrange(0, len(array_of_Classes) - 1):
                for b in xrange(array_of_Classes[a], array_of_Classes[a + 1]):
                    counter_lines_in_Class += 1
                array_lines_in_Class.append(counter_lines_in_Class)
                counter_lines_in_Class = 0
            """  
			Calculation of the LOC for the last Class of each Program: 
			From where the Class starts, to the last line of code.
			Excluding the necessary execution and the condition
			to make it portable.
			"""
            for c in xrange(array_of_Classes[(len(array_of_Classes) - 1)],
                            len(self.file_content)):
                counter_lines_in_Class += 1
                if (len(self.file_content) - c) <= 4:
                    counter_lines_in_Class -= 1

        #  We append the data of the last Class to the array, so it can be mapped
        array_lines_in_Class.append(counter_lines_in_Class)
        counter_lines_in_Class = 0
        """
		Finally, we print the result obtained
		in a legible and user-friendly way.
		"""
        print "Program Lines Counted: "
        for z in xrange(0, len(array_of_Classes)):
            print "\n\tPart Name: ", self.file_content[array_of_Classes[z]]
            print "\tNumber of Items: ", array_Def_in_Class[z]
            print "\tPart Size: ", array_lines_in_Class[z]
        print "\n\tTotal lines of code: ", total_lines_of_code