def manufactureItems(mode='market', nItems=10, disregardOwnedMats=False, report=True, typeIDs=None, ignoreTypeID=None): """choses items, calculates materials, presents results""" if not typeIDs: typeIDs = chooseItems(mode=mode, nItems=nItems) #logic to remove certain typeIDs if ignoreTypeID: for ignored in ignoreTypeID: if ignored in typeIDs: del typeIDs[ignored] #calculate total components and additional raw materials needed for typeID production materials = {} components = {} for typeID in typeIDs: manufSize = typeIDs[typeID] reqMats = requiredMaterials(typeID, manufSize=manufSize) for matID in reqMats: if utils.buildable(matID): components = utils.integrate(components, matID, reqMats[matID]) else: materials = utils.integrate(materials, matID, reqMats[matID]) #subtract already owned components from the list if not disregardOwnedMats: ownedMats = utils.getOwnedMaterials() components, ownedMats = utils.dictSubtraction(components, ownedMats) #further break down components into raw materials for componentID in components: producerID = utils.producerID(componentID) reqMats = requiredMaterials(producerID, manufSize=components[componentID]) for matID in reqMats: materials = utils.integrate(materials, matID, reqMats[matID]) #subtract already owned raw materials from the list if not disregardOwnedMats: materials, ownedMats = utils.dictSubtraction(materials, ownedMats) #final report if report: materialReport(typeIDs, components, materials) else: return materials
def integrate_value(samples, key): epoch = utils.EPOCH x = list((s['timestamp'] - epoch).total_seconds() for s in samples) y = list(s[key] for s in samples) I = utils.integrate(x, y) return I
def postintegrate(): function= request.forms.get('function') lower= int(request.forms.get('lower')) upper= int(request.forms.get('upper')) integrate= round(utils.integrate(function, lower, upper), 2) return ''' the results: {}<br /><br /> <a href= https://boiling-beach-99041.herokuapp.com>Home</a> '''.format(integrate)
def test_integrate(self): self.assertEqual(utils.integrate('x', 0, 1), 0.5) self.assertEqual(utils.integrate('x', 0, 1), 0.5) self.assertEqual(utils.integrate('x', 0, 1), 0.5) self.assertEqual(utils.integrate('x', 0, 1), 0.5) self.assertEqual(utils.integrate('x', 0, 1), 0.5) self.assertEqual(utils.integrate('x', 0, 1), 0.5) self.assertEqual(utils.integrate('x', 0, 1), 0.5)
def Answer_integ(self, function, lower, upper): try: a = int(lower) b = int(upper) integrate = utils.integrate(function, a, b) return {"function": function, "result": integrate} except: pass
def integral(self, var): """ Flux surface integral result = int var dl where dl is the poloidal arc length """ # Integrate ( var * dl/dtheta ) dtheta return integrate(lambda x: var(x) * self._dldtheta(x), 0, 2 * pi)
def integral(self, var): """ Flux surface integral result = int var dl where dl is the poloidal arc length """ # Integrate ( var * dl/dtheta ) dtheta return integrate(lambda x: var(x) * self._dldtheta(x), 0, 2 * pi)
def intg_page(): decoded = request.forms.decode("utf-8") try: a = int(decoded.get("Lower")) b = int(decoded.get("Upper")) except ValueError: return "<h1> Please enter a <strong>valid</strong> Lower/Upper boundary</h1>" function = decoded.get("func") return "The approximation of {} from {} to {} is {}".format(function, a, b, round(integrate(function, a, b), 4))
def requiredMaterials(typeID, componentsOnly=False, manufSize=None): """return the component materials needed for manufSize number of items""" bpItems = utils.getBlueprintsItems(typeID) if not manufSize: manufSize = utils.size(typeID)[1] #modify runs if they are negative (i.e, if a bpo is available) for bp in bpItems: ME = bp[0] runs = bp[1] if runs == -1: #bpos have -1 runs bpItems = [[ME, 10000000]] break #logic that decides which bpc to use given the amount of things to produce sortedBPCs = sorted(bpItems, key=lambda x: x[0], reverse=True) totalMaterialCost = {} for BP in sortedBPCs: ME = BP[0] runs = BP[1] if manufSize - runs > 0: modMaterialCost = modifiedMaterials(typeID, runs, ME) for matID in modMaterialCost: if componentsOnly and not utils.buildable(matID): continue totalMaterialCost = utils.integrate(totalMaterialCost, matID, modMaterialCost[matID]) manufSize = manufSize - runs elif manufSize - runs <= 0: modMaterialCost = modifiedMaterials(typeID, manufSize, ME) for matID in modMaterialCost: if componentsOnly and not utils.buildable(matID): continue totalMaterialCost = utils.integrate(totalMaterialCost, matID, modMaterialCost[matID]) break return totalMaterialCost
def Delay(self, delayProf): """ Compute the delayed profile composed of *self* profile and *delayProf*, received by a node for which this *self* profile is the output profile on the sender side. The delay profile describes the delay as a function of time for the link. This function implements the operation: .. math:: o[t + \delta[t]] = l[t] Where * :math:`\delta[t]` is the delay profile * :math:`l[t]` is the profile transmitted into the link (*self*) * :math:`o[t]` is the output profile received at the other end of the link :rtype: :class:`Profile`, :math:`o[t]` :param in delayProf: :class:`Profile` describing the delay """ delays = delayProf.entries['latency'] all0 = True for time, delay in delays: if delay != 0: all0 = False if all0: return copy.deepcopy(self) datas = self.entries['data'] endTime = datas[-1][0] times = [ x[0] for x in delays ] times.extend( [ x[0] for x in datas ] ) times = sorted(list(set(times))) newDatas = [] for t in times: d = utils.get_value_at_time(datas, t) delay = utils.get_value_at_time(delays, t, interpolate = 'latency' in self.interpolated_profiles) newDatas.append([ t + delay, d ]) newDatas = utils.remove_degenerates(newDatas) newDatas, remainder = utils.split(newDatas, endTime) if remainder: t = -remainder[0][0] utils.shift(remainder, t) r_slopes = utils.derive(remainder) d_slopes = utils.derive(newDatas) d_slopes = utils.add_values(d_slopes,r_slopes) newDatas = utils.integrate(d_slopes, endTime) retProf = Profile() retProf.entries['data'] = newDatas retProf.Derive() return retProf
def trappedFraction(surf): """ Calculate the trapped particle fraction Parameters ---------- surf = Flux surface object .max( f(theta) ) Maximum value over theta .B(theta) Magnetic field strength [T] .Bsqav() < B^2 > .average( func(theta) ) Flux surface average """ try: # See if surface already has a trapped fraction value ft = surf.trappedFraction # If so, return it return ft except: pass # Just catch the error try: if surf.psinorm < 1e-2: surf.trappedFraction = 0. return 0. except: pass bigint = integrate( lambda rla: rla / surf.average( lambda x: sqrt(1. - rla*surf.B(x)) ), 0.0, # Lower limit 1./surf.max(surf.B)) # Upper limit # Set a variable in surface object so we don't have to calculate all that again surf.trappedFraction = 1. - 3.*surf.Bsqav() * bigint / 4. # Sanity check the value if (surf.trappedFraction < 0.) or (surf.trappedFraction > 1.): raise ValueError("Trapped fraction ft must be between 0 and 1") return surf.trappedFraction
def test_integrate(self): self.assertEqual(utils.integrate('x**3', 0, 2), 4.0)
def test_integrate(self): self.assertEqual(round(-(4/3), 1), round(utils.integrate('x ** 2 - 1',-1,1),1))
def test_integrate ( self): self.assertEqual (utils.integrate ('x ** 2 - 1', -1, 1), 2) self.assertEqual (utils.integrate ('x ** 2 - 5', -9, 1), 2)
def test_integrate(self): self.assertAlmostEqual(utils.integrate("x", 0, 1), 1/2 , places = 3) self.assertAlmostEqual(utils.integrate("x**2", 0, 3), 9, places = 3) self.assertAlmostEqual(utils.integrate("x**4", 0, 1), 1/5, places = 3)
def test_integrate(self): self.assertTrue(-1.34< utils.integrate('x ** 2 - 1', -1, 1) < -1.33) pass
def test_integrate(self): self.assertAlmostEqual(utils.integrate("2*x", -4, 2), -12)
def test_integrate(self): self.assertTrue(utils.integrate('x', 0, 4) >= 7.9 and utils.integrate('x', 0, 4) <= 8.1) self.assertTrue(utils.integrate('7', 3, 5) >= 13.9 and utils.integrate('7', 3, 5) <= 14.1) pass
def test_integrate(self): self.assertEqual(utils.integrate('x ** 2 - 1', -1, 1), -1.3333)
def test_integrate(self): self.assertTrue(utils.integrate('x**2 - 1', -1, 1) > -1.4) self.assertTrue(utils.integrate('x**2 - 1', -1, 1) < -1.2)
def test_integrate(self): self.assertAlmostEqual(utils.integrate('x^2', 1, 2), 7 / 3) pass
def test_integrate(self): self.assertEqual(utils.integrate('1', -4, 12) , 16) self.assertEqual(utils.integrate('2 * x + 1',-2, 2), 4) self.assertEqual(utils.integrate('3 * x**3 + 3*x + 2', 0, 1), 4.25)
def test_integrate(self): self.assertEqual(utils.integrate('1', 0, 1), 1)
def test_integrate(self): self.assertAlmostEqual(utils.integrate("x", 0, 9), 40.5) pass
def test_integrate(self): # À compléter... self.assertAlmostEqual(utils.integrate("2*x", -4, 2), -12)
def test_integrate(self): self.assertAlmostEqual(utils.integrate('x ** 2 - 1', -1, 1), -1.333, 3) #cas initial qui permet d'avoir un etalon, c'est toujours vrai self.assertAlmostEqual(utils.integrate('x ** 2',-2,1), -3,3 ) pass
def test_integrate(self): self.assertEqual(utils.integrate("x", 0, 2), 2) pass
def test_integrate(self): self.assertAlmostEqual(utils.integrate(' x ** 2 ',0,3), 9) #trouver solution pour avoir une meilleur fonction intégrale self.assertAlmostEqual(utils.integrate(' x ** 4',0,3), (48.6)) pass
def test_integrate(self): return self.assertEqual(utils.integrate(0, 1, 2), 1)
def test_integrate(self): self.assertTrue(15.8 < utils.integrate("2*x", 0, 4), 16 < 16.1) # Comme on APPROXIME l'intégrale, on ne pourra jamais obtenir la valeur exacte de -4/3 self.assertTrue(-1.5 < utils.integrate("x**2-1", -1, 1) < -1.2)
def test_integrate(self): self.assertEqual(utils.integrate('x ** 2 - 1', -1, 1), -1.3333319999999986)
def test_integrate(self): y = 1 self.assertEqual(utils.integrate((lambda x: 1), 0, 1), y) pass
def test_integrate(self): self.assertAlmostEquals(utils.integrate('x', 0, 1), 0.5)
def test_integrate(self): self.assertEqual(utils.integrate('x**2', 0, 2), round(8 / 3, 3))
def test_integrate(self): self.assertEqual(utils.integrate("5", 4, 6), 10) self.assertEqual(utils.integrate("x", 3, 9), 36) self.assertEqual(utils.integrate("5*x**2+3*x-9", -3, 12), 5992 / 2)
def test_integrate(self): self.assertAlmostEqual(utils.integrate("x**2", 0, 1), 1 / 3, places=3) self.assertNotAlmostEqual(utils.integrate("x**2", 0, -1), 1 / 3, places=3)
def test_integrate(self): self.assertEqual(utils.integrate('3',0,3),9) with self.assertRaises(TypeError): utils.integrate('x^2','a',4)
def test_integrate(self): # À compléter... self.assertEqual(utils.integrate("x", 0, 2), (2))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Mar 2 14:31:18 2021 @author: usera """ import gmsh, sys, time import dolfin import numpy as np from utils import Expression, DOLFIN_Mesh, addBox, addRectangle, integrate model = gmsh.model gmsh.initialize(sys.argv) gmsh.option.setNumber("General.Terminal", 1) gmsh.option.setNumber("Mesh.MshFileVersion", 2.0) gmsh.option.setNumber("Mesh.SaveAll", 0) box = addBox(0, 0, 0, 1, 1, 1, meshsize=0.1) box2 = addBox(0, 0, -0.5, 1, 1, 0.5, meshsize=0.1) rect = addRectangle(0, 0, 0, 0.1, 0.8, meshsize=0.01) integrate([[3, box]], [[2, rect]]) model.occ.removeAllDuplicates() integrate([[3, box2]], [[2, rect]]) model.mesh.generate(3) gmsh.write('bilayer_with_circuit_mesh.vtk') gmsh.finalize()
def test_integrate(self): self.assertEqual(utils.integrate('x ** 2 - 1', -1, 1),None)
def test_integrate(self): # À compléter... self.assertEqual(utils.integrate('x ** 2 - 1', -1, 1), round(-4.0/3, 15))
def Integrate(self, time): """Integrates the slope entries to produce data entries up to *time*""" self.AggregateSlopes() self.entries['data'] = utils.integrate(self.entries['slope'], time)
def test_integrate(self): # À compléter... self.assertEqual(utils.integrate('x**2 - 1',-1,1),-1.333,3)
def test_integrate(self): # À compléter... self.assertEqual(utils.integrate('x',0,10),50) self.assertEqual(utils.integrate('x**2 -1 ',-1,1),(-4/3))