Ejemplo n.º 1
0
    def test_formatting(self):
        formatted = dexi._format_number(1.5)
        self.assertEqual(formatted, "1.50")

        formatted = dexi._format_number(2)
        self.assertEqual(formatted, "2.00")

        formatted = dexi._format_number(1.55555)
        self.assertEqual(formatted, "1.56")

        self.assertRaises(ValueError, dexi._format_number, "foo")
Ejemplo n.º 2
0
    def test_formatting(self):
        formatted = dexi._format_number(1.5)
        self.assertEqual(formatted, "1.50")

        formatted = dexi._format_number(2)
        self.assertEqual(formatted, "2.00")

        formatted = dexi._format_number(1.55555)
        self.assertEqual(formatted, "1.56")

        self.assertRaises(ValueError, dexi._format_number, "foo")
Ejemplo n.º 3
0
def animation():
    raw_function = ""
    if "names" in request.form:
        # if "names" is in the request, it means it was called from the already
        # created derivatives - the user changed the inputs and retried the
        # derivative creation
        values = {}
        # we read the fields in the request and parse out those that start with a v
        for field in request.form:
            if field[0] == "v":
                # the values and the entries are put into a dictionary
                # before that the keys have "v"s removed and cast to int
                tmp_f = int(field.replace("v", ""))
                values[tmp_f] = request.form[field]

        value_list = []
        # we sort the keys of the dictionary, to get the initial order
        # and put the values into a value list
        for field in sorted(values):
            value_list.append(values[field])

        # function is described in three lines
        function_description = []
        # output values joined, delimited with a comma
        function_description.append(",".join(value_list))
        # names are delimited by a comma (already in the request)
        function_description.append(request.form["names"])
        # multiplicities are delimited by a comma (already in the request)
        function_description.append(request.form["multiplicity"])

        # the raw function is represented as a new-line delimitied string
        raw_function = str("\n".join(function_description))

    else:
        return _MISSING_ARGUMENTS

    # we are interested in the time that took for generating the animation
    t = time()
    # we parse the function, getting the actual function, arguments, needed evaluations
    # success status and possible message
    function, arguments, evaluations, success, message = parse_function(
        raw_function)

    if success:
        # if the previous step succeeded we can construct the function, get derivatives,
        # evaluations and the possible image
        anim_file_name = _create_animation(function, arguments)
        print "Function animation needed {0}s to execute!".format(
            _format_number(time() - t))
    else:
        return _COULD_NOT_PARSE_FUNCTION.format(message)

    # the derivatives page is rendered
    return anim_file_name
Ejemplo n.º 4
0
def animation():
    raw_function = ""
    if "names" in request.form:
        # if "names" is in the request, it means it was called from the already
        # created derivatives - the user changed the inputs and retried the
        # derivative creation
        values = {}
        # we read the fields in the request and parse out those that start with a v
        for field in request.form:
            if field[0] == "v":
                # the values and the entries are put into a dictionary
                # before that the keys have "v"s removed and cast to int
                tmp_f = int(field.replace("v",""))
                values[tmp_f] = request.form[field]

        value_list = []
        # we sort the keys of the dictionary, to get the initial order
        # and put the values into a value list
        for field in sorted(values):
            value_list.append(values[field])

        # function is described in three lines
        function_description = []
        # output values joined, delimited with a comma
        function_description.append(",".join(value_list))
        # names are delimited by a comma (already in the request)
        function_description.append(request.form["names"])
        # multiplicities are delimited by a comma (already in the request)
        function_description.append(request.form["multiplicity"])

        # the raw function is represented as a new-line delimitied string
        raw_function = str("\n".join(function_description))

    else:
        return _MISSING_ARGUMENTS

    # we are interested in the time that took for generating the animation
    t = time()
    # we parse the function, getting the actual function, arguments, needed evaluations
    # success status and possible message
    function, arguments, evaluations, success, message = parse_function(raw_function)

    if success:
        # if the previous step succeeded we can construct the function, get derivatives,
        # evaluations and the possible image
        anim_file_name = _create_animation(function, arguments)
        print "Function animation needed {0}s to execute!".format(_format_number(time() - t))
    else:
        return _COULD_NOT_PARSE_FUNCTION.format(message)

    # the derivatives page is rendered
    return anim_file_name 
Ejemplo n.º 5
0
def derivatives():
    # the path which serves post requests for creating derivatives
    raw_function = ""
    if "names" in request.form:
        # if "names" is in the request, it means it was called from the already
        # created derivatives - the user changed the inputs and retried the
        # derivative creation
        values = {}
        # we read the fields in the request and parse out those that start with a v
        for field in request.form:
            if field[0] == "v":
                # the values and the entries are put into a dictionary
                # before that the keys have "v"s removed and cast to int
                tmp_f = int(field.replace("v",""))
                values[tmp_f] = request.form[field]

        value_list = []
        # we sort the keys of the dictionary, to get the initial order
        # and put the values into a value list
        for field in sorted(values):
            value_list.append(values[field])

        # function is described in three lines
        function_description = []
        # output values joined, delimited with a comma
        function_description.append(",".join(value_list))
        # names are delimited by a comma (already in the request)
        function_description.append(request.form["names"])
        # multiplicities are delimited by a comma (already in the request)
        function_description.append(request.form["multiplicity"])

        # the raw function is represented as a new-line delimitied string
        raw_function = str("\n".join(function_description))

    elif "function" in request.form:
        # if function is present in request, we read it directly
        # parsing is done afterwards
        raw_function = request.form["function"]
    else:
        # if neither of them are present, we return error status
        entries = {"raw_function": raw_function,
                   "ok": False,
                   "message": "Unsupported operation!",
                   "title": content._TITLE,
                   "subtitle": content._SUBTITLE,
                   "about": content._ABOUT,
                   "license": content._GPL,
        }
        # render the derivatives page
        return render_template("derivatives.html", entries=entries)

    # we are interested in the time that took for generating the derivatives,
    # evaluations and images
    t = time()

    # we parse the function, getting the actual function, arguments, needed evaluations
    # success status and possible message
    function, arguments, evaluations, success, message = parse_function(raw_function)

    # variables are prepared for filling in - these are defaults if anything goes wrong
    raw_function = raw_function.replace("\r", "")
    raw_function = raw_function.split("\n")
    derivatives = None
    success1 = False
    message1 = ""
    multiplicities = ""
    names = ""
    image = ""
    if success:
        # if the previous step succeeded we can construct the function, get derivatives,
        # evaluations and the possible image
        names = ",".join(arguments)
        multiplicities = raw_function[2]
        derivatives, evaluations, image, success1, message1 = get_derivatives(function, evaluations, arguments)
        print "Query needed {0}s to execute!".format(_format_number(time() - t))

    # form a dictionary to return to the user
    entries = {"raw_function": raw_function,
               "ok": success and success1,
               "message": " ".join([message, message1]),
               "function": function,
               "arguments": arguments,
               "derivatives": derivatives,
               "title": content._TITLE,
               "subtitle": content._SUBTITLE,
               "about": content._ABOUT,
               "license": content._GPL,
               "names": names,
               "multiplicities": multiplicities,
               "evaluations": evaluations,
               "image": image
    }

    # the derivatives page is rendered
    return render_template("derivatives.html", entries=entries)
Ejemplo n.º 6
0
def derivatives():
    # the path which serves post requests for creating derivatives
    raw_function = ""
    if "names" in request.form:
        # if "names" is in the request, it means it was called from the already
        # created derivatives - the user changed the inputs and retried the
        # derivative creation
        values = {}
        # we read the fields in the request and parse out those that start with a v
        for field in request.form:
            if field[0] == "v":
                # the values and the entries are put into a dictionary
                # before that the keys have "v"s removed and cast to int
                tmp_f = int(field.replace("v", ""))
                values[tmp_f] = request.form[field]

        value_list = []
        # we sort the keys of the dictionary, to get the initial order
        # and put the values into a value list
        for field in sorted(values):
            value_list.append(values[field])

        # function is described in three lines
        function_description = []
        # output values joined, delimited with a comma
        function_description.append(",".join(value_list))
        # names are delimited by a comma (already in the request)
        function_description.append(request.form["names"])
        # multiplicities are delimited by a comma (already in the request)
        function_description.append(request.form["multiplicity"])

        # the raw function is represented as a new-line delimitied string
        raw_function = str("\n".join(function_description))

    elif "function" in request.form:
        # if function is present in request, we read it directly
        # parsing is done afterwards
        raw_function = request.form["function"]
    else:
        # if neither of them are present, we return error status
        entries = {
            "raw_function": raw_function,
            "ok": False,
            "message": "Unsupported operation!",
            "title": content._TITLE,
            "subtitle": content._SUBTITLE,
            "about": content._ABOUT,
            "license": content._GPL,
        }
        # render the derivatives page
        return render_template("derivatives.html", entries=entries)

    # we are interested in the time that took for generating the derivatives,
    # evaluations and images
    t = time()

    # we parse the function, getting the actual function, arguments, needed evaluations
    # success status and possible message
    function, arguments, evaluations, success, message = parse_function(
        raw_function)

    # variables are prepared for filling in - these are defaults if anything goes wrong
    raw_function = raw_function.replace("\r", "")
    raw_function = raw_function.split("\n")
    derivatives = None
    success1 = False
    message1 = ""
    multiplicities = ""
    names = ""
    image = ""
    if success:
        # if the previous step succeeded we can construct the function, get derivatives,
        # evaluations and the possible image
        names = ",".join(arguments)
        multiplicities = raw_function[2]
        derivatives, evaluations, image, success1, message1 = get_derivatives(
            function, evaluations, arguments)
        print "Query needed {0}s to execute!".format(_format_number(time() -
                                                                    t))

    # form a dictionary to return to the user
    entries = {
        "raw_function": raw_function,
        "ok": success and success1,
        "message": " ".join([message, message1]),
        "function": function,
        "arguments": arguments,
        "derivatives": derivatives,
        "title": content._TITLE,
        "subtitle": content._SUBTITLE,
        "about": content._ABOUT,
        "license": content._GPL,
        "names": names,
        "multiplicities": multiplicities,
        "evaluations": evaluations,
        "image": image
    }

    # the derivatives page is rendered
    return render_template("derivatives.html", entries=entries)