Ejemplo n.º 1
0
    def weight(self, quantity=1, volumeunits="cc", weightunits="grams"):

        """
        Returns the weight of a specified volume of the material.

        Arguments:
        quantity -- the volume
        volumeunits -- units in which 'quantity' is stated
        weightunits -- units for which to return the weight

        For example, weight(35, "in3", "pounds") will return the weight,
        in pounds, of 35 cubic inches of the material.
        """

        cc_quant = convert(quantity, volumeunits, "cc")
        w_grams = cc_quant * self._specific_gravity
        return convert(w_grams, "grams", weightunits)
Ejemplo n.º 2
0
    def convert(self, conversion):
        """Convert value using function func.

        :param conversion: Conversion function name
        :type conversion: String|None
        """
        if self.value is None or conversion is None:
            return
        self.value = convert(conversion, self.value)
Ejemplo n.º 3
0
    def convert(self, conversion):
        """Convert value using function func.

        :param conversion: Conversion function name
        :type conversion: String|None
        """
        if self.value is None or conversion is None:
            return
        self.value = convert(conversion, self.value)
Ejemplo n.º 4
0
    def GET(self, *uri, **params):
        if len(uri) != 1:
            # Whathever the uri was, it's not valid
            # Set the appropriate HTTP status
            cherrypy.response.status = 404  # Not Found
            return "Command not supported!"

        # Shutdown on "shutdown". Used for debugging purposes
        if uri[0] == "shutdown":
            cherrypy.engine.exit()
            return ""

        if uri[0] == "converter":
            # Check if the parameters are valid
            if len(
                    params
            ) != 3 or "value" not in params or "originalUnit" not in params or "targetUnit" not in params:
                cherrypy.response.status = 400  # Bad Request
                return "Wrong parameters!<br>Usage: converter?value=&lt;val&gt;&originalUnit=&lt;orig&gt;&targetUnit=&lt;trgt&gt;."

            originalUnit = params["originalUnit"].upper()
            targetUnit = params["targetUnit"].upper()

            # Check if the units are valid
            if originalUnit not in self.validUnits or targetUnit not in self.validUnits:
                cherrypy.response.status = 400  # Bad Request
                return "Invalid temperature unit!<br>Valid units are:<ul><li>C - Celsius</li><li>K - Kelvin</li><li>F - Fahrenheit</li></ul>"

            try:
                originalValue = float(params["value"])
            except:
                # The numerical value is invalid!
                cherrypy.response.status = 400  # Bad Request
                return "Invalid temperature value!"

            # Perform the conversion
            try:
                targetValue = conversions.convert(originalValue, originalUnit,
                                                  targetUnit)
            except ValueError as e:
                cherrypy.response.status = 400  # Bad Request
                return str(e)

            return self.buildJSON(originalValue, originalUnit, targetValue,
                                  targetUnit)

        if uri[0] == "log":
            # Log all the temperature data received so far
            return json.dumps(
                self.listValue
            )  # Use json.dumps to print the list instead of just converting
            # it into a string to print with the double quotes to be compliant with JSON

        # The command is not valid
        cherrypy.response.status = 404  # Not Found
        return "Command not supported!"
Ejemplo n.º 5
0
	def perimeter(self, units=None):

		"""
		Returns the perimeter of the shape in user units.

		Arguments:
		units -- units in which to return perimeter, default is
		internal length units
		"""

		if not units:
			units = self._units
		else:
			validate_length(units)

		perim_int = self._perimeter_internal_units()
		return convert(perim_int, self._units, units)
Ejemplo n.º 6
0
	def area(self, areaunits=None):

		"""
		Returns the area of the shape in user units.

		Arguments:
		areaunits -- units in which to return area, default is
		squared internal length units
		"""

		if not areaunits:
			areaunits = self._units_area
		else:
			validate_area(areaunits)

		area_int = self._area_internal_units()
		return convert(area_int, self._units_area, areaunits)
Ejemplo n.º 7
0
    def volume(self, volumeunits=None):

        """
        Returns the volume of the cuboid in user units.

        Arguments:
        volumeunits -- units in which to return volume, default is
        cubed internal length units.
        """

        if not volumeunits:
            volumeunits = self._units_volume
        else:
            validate_volume(volumeunits)

        volume_int = self._volume_internal_units()
        return convert(volume_int, self._units_volume, volumeunits)
Ejemplo n.º 8
0
    def base_surface_area(self, areaunits=None):

        """
        Returns the base surface area of the cylinder in user units.

        Arguments:
        areaunits -- units in which to return surface area, default is
        squared internal length units.
        """

        if not areaunits:
            areaunits = self._units_area
        else:
            validate_area(areaunits)

        area_int = self._base_sa_internal_units()
        return convert(area_int, self._units_area, areaunits)
Ejemplo n.º 9
0
                mainIndex = mainData.loc[mainData['key'] ==
                                         currKey]['lastUpdated'].index[0]
                # Since mainTime is smaller, we have to update the values
                if mainTime < fileRow['dateAdded']:
                    mainData.loc[mainIndex, 'description'] = row['description']
                    mainData.loc[mainIndex, 'phone'] = row['phone']
                    mainData.loc[mainIndex, 'hours'] = row['hours']
                    mainData.loc[mainIndex, 'website'] = row['website']
                    mainData.loc[mainIndex, 'lastUpdated'] = currDateAdded
                # Do nothing, as we already have the same > better dataset
                else:
                    continue
        # Now that we have finished looping through everything, we should make sure the seen files is updated
        # If not in the seenFiles, add it
        if (currFileName not in seenFiles):
            newRow = {'name': currFileName, 'dateAdded': currDateAdded}
            seenFiles = seenFiles.append(newRow, ignore_index=True)
        # Just update it if it's already in
        else:
            seenFiles.loc[currFileName, 'dateAdded'] = currDateAdded
    else:
        # We have no need to look at this current file, as it hasn't been updated, so let's continue.
        continue

# Now let's save everything so we can access it
mainData.to_csv('../finalData/mainData.csv', index=False)
seenFiles.to_csv('../openedSheets.csv', index=False)

# Now let's call the conversions.
print(conversions.convert())