Example #1
0
    def test_animation(self):
        anim_file_name = dexi._create_animation("", [])
        self.assertEqual(anim_file_name, "")

        anim_file_name = dexi._create_animation("", ["f"])
        self.assertEqual(anim_file_name, "")

        anim_file_name = dexi._create_animation("", ["f", "s", "t"])
        self.assertEqual(anim_file_name, "")

        content._DEFAULT_IMAGE_PATH = ""
        function = [[(0, 0), 0], [(0, 1), 1], [(1, 0), 1], [(1, 1), 2]]
        anim_file_name = dexi._create_animation(function, ["f", "s"])

        self.assertRegexpMatches(anim_file_name, "[a-zA-Z0-9]{10}\.gif")
        self.assertTrue(os.path.isfile(anim_file_name))
        os.remove(anim_file_name)
Example #2
0
    def test_animation(self):
        anim_file_name = dexi._create_animation("", [])
        self.assertEqual(anim_file_name, "")

        anim_file_name = dexi._create_animation("", ["f"])
        self.assertEqual(anim_file_name, "")

        anim_file_name = dexi._create_animation("", ["f", "s", "t"])
        self.assertEqual(anim_file_name, "")

        content._DEFAULT_IMAGE_PATH = ""
        function = [[(0, 0), 0], [(0, 1), 1], [(1, 0), 1], [(1, 1), 2]]
        anim_file_name = dexi._create_animation(function, ["f", "s"])

        self.assertRegexpMatches(anim_file_name, "[a-zA-Z0-9]{10}\.gif")
        self.assertTrue(os.path.isfile(anim_file_name))
        os.remove(anim_file_name)
Example #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
Example #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