[go: up one dir, main page]

CN114791803A - Algorithmic animation generation method and system based on proxy mode and front-end and back-end separation - Google Patents

Algorithmic animation generation method and system based on proxy mode and front-end and back-end separation Download PDF

Info

Publication number
CN114791803A
CN114791803A CN202210492780.0A CN202210492780A CN114791803A CN 114791803 A CN114791803 A CN 114791803A CN 202210492780 A CN202210492780 A CN 202210492780A CN 114791803 A CN114791803 A CN 114791803A
Authority
CN
China
Prior art keywords
code
end server
animation
algorithm
server
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210492780.0A
Other languages
Chinese (zh)
Inventor
乜鹏
李航宇
王浩伟
陶稳冲
吕尤
黎明杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nankai University
Original Assignee
Nankai University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nankai University filed Critical Nankai University
Priority to CN202210492780.0A priority Critical patent/CN114791803A/en
Publication of CN114791803A publication Critical patent/CN114791803A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T13/00Animation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Processing Or Creating Images (AREA)

Abstract

The disclosure belongs to the technical field of internet, and particularly relates to an algorithm animation generation method and system based on agent mode and front-back end separation, which comprises the following steps: loading an algorithm animation display page through a front-end server, and mapping the animation display page to a preset position; generating a self-defined code in a front-end server based on the information required by the code, and initiating a code submitting request to a back-end server; the back-end server receives a code submitting request initiated by the front-end server, processes the received code, generates code animation data and returns the generated code animation data to the front-end server; and the front-end server receives the code animation data returned by the back-end server and generates algorithm animation by combining the mapped preset position.

Description

基于代理模式和前后端分离的算法动画生成方法及系统Algorithmic animation generation method and system based on proxy mode and front-end and back-end separation

技术领域technical field

本公开属于互联网技术领域,具体涉及一种基于代理模式和前后端分离的算法动画生成方法及系统。The present disclosure belongs to the field of Internet technologies, and in particular relates to an algorithm animation generation method and system based on an agent mode and separation of front and back ends.

背景技术Background technique

本部分的陈述仅仅是提供了与本公开相关的背景技术信息,不必然构成在先技术。The statements in this section merely provide background information related to the present disclosure and do not necessarily constitute prior art.

随着互联网技术的发展,计算机技术变得越来越热门,算法在计算机技术中有着举足轻重的作用,算法的学习却很枯燥且困难。With the development of Internet technology, computer technology has become more and more popular. Algorithms play a pivotal role in computer technology, but algorithm learning is boring and difficult.

据发明人了解,现有技术中缺乏降低算法学习难度的相关研究。As far as the inventors know, there is a lack of relevant research on reducing the difficulty of algorithm learning in the prior art.

发明内容SUMMARY OF THE INVENTION

为了解决上述问题,本公开提出了一种基于代理模式和前后端分离的算法动画生成方法及系统,基于代理模式、前端Vue组件技术、后端服务器技术和前后端分离技术,通过生成算法代码的动画数据,根据动画数据生成可供观看的算法动画,将算法转换成令人舒适的动画供人观看学习,有效降低了算法学习的难度。In order to solve the above problems, the present disclosure proposes an algorithm animation generation method and system based on proxy mode and front-end and back-end separation. Animation data, generate watchable algorithm animation according to the animation data, and convert the algorithm into a comfortable animation for people to watch and learn, which effectively reduces the difficulty of algorithm learning.

根据一些实施例,本公开的第一方案提供了一种基于代理模式和前后端分离的算法动画生成方法,采用如下技术方案:According to some embodiments, the first solution of the present disclosure provides an algorithm animation generation method based on proxy mode and front-end and back-end separation, and adopts the following technical solutions:

一种基于代理模式和前后端分离的算法动画生成方法,包括:An algorithm animation generation method based on proxy mode and separation of front and back ends, including:

通过前端服务器加载算法动画展示页面,将所述动画展示页面映射到预设位置;Load the algorithm animation display page through the front-end server, and map the animation display page to a preset position;

基于代码所需信息在前端服务器中生成自定义代码,向后端服务器发起提交代码请求;Generate custom code in the front-end server based on the information required by the code, and initiate a code submission request to the back-end server;

后端服务器接收到前端服务器所发起的提交代码请求,处理所接收到的代码,生成代码动画数据,将所生成的代码动画数据返回至前端服务器;The back-end server receives the code submission request initiated by the front-end server, processes the received code, generates code animation data, and returns the generated code animation data to the front-end server;

前端服务器接收后端服务器所返回的代码动画数据,结合所映射的预设位置生成算法动画。The front-end server receives the code animation data returned by the back-end server, and generates algorithm animation in combination with the mapped preset positions.

作为进一步的技术限定,在加载算法动画展示页面之前,前端服务器进行初始化,具体为:前端服务器向Nginx服务器请求静态资源,使用axios请求后端服务器的数据资源,在前端服务器请求后端数据资源的时候,先向Nginx服务器发起请求,Nginx服务器请求转发到对应的后端服务器中进行处理。As a further technical limitation, before loading the algorithm animation display page, the front-end server is initialized, specifically: the front-end server requests static resources from the Nginx server, uses axios to request the data resources of the back-end server, and requests the back-end data resources from the front-end server. At this time, first initiate a request to the Nginx server, and the Nginx server request is forwarded to the corresponding back-end server for processing.

作为进一步的技术限定,在加载算法动画展示页面的过程中,通过前端服务器的算法动画组件播放算法动画的Vue组件,所述Vue组件采用含canvas画布的DOM元素,通过JavaScript在含canvas画布的DOM元素所在的区域进行算法动画的绘制和生成。As a further technical limitation, in the process of loading the algorithm animation display page, the Vue component of the algorithm animation is played through the algorithm animation component of the front-end server. The area where the element is located is drawn and generated by algorithmic animation.

进一步的,在将所述动画展示页面映射到预设位置的过程中,采用路由将各个动画展示页面组件映射到相应的位置,即使用所述Vue组件框架中的路由插件Vue-Router来映射前端服务器中所加载生成的算法动画展示页面,按照Vue路由规则进行算法动画展示页面各个Vue组件的匹配,将算法动画展示页面映射到相匹配的预设位置。Further, in the process of mapping the animation display page to the preset position, each animation display page component is mapped to the corresponding position by routing, that is, the routing plug-in Vue-Router in the Vue component framework is used to map the front end. The generated algorithm animation display page loaded in the server matches each Vue component of the algorithm animation display page according to the Vue routing rules, and maps the algorithm animation display page to the matching preset position.

作为进一步的技术限定,用户选择运行模式、编程语言、设置代码执行标签和输入测试样例,编写自定义代码;前端服务器发起POST请求,Nginx服务器将请求转发到后端服务器所对应的控制器中,向后端服务器发起提交代码请求。As a further technical limitation, the user selects the running mode, programming language, sets the code execution label and enters the test sample, and writes custom code; the front-end server initiates a POST request, and the Nginx server forwards the request to the controller corresponding to the back-end server , initiate a code submission request to the backend server.

作为进一步的技术限定,后端服务器获取用户POST请求中的编程语言类型信息,根据编程语言类型信息启动后端服务器的API来创建相应的Docker容器,后端服务器在创建容器的过程中读取POST请求中发来的运行模式,代码执行标签,存入数据库;后端服务器读取POST请求中的用户自定义代码,将用户输入的测试样例作为数据结构代理类的原始数据注入到代码文件之中,将代码文件保存至容器创建的数据卷中以供容器内部访问并执行代码;程序运行结束后,代理类中存储的算法数据结构的改变序列将会被输出出来,后端服务器的服务程序捕获到输出的信息,用户将捕获到数据结构的改变序列的输出信息和POST请求发来的用户所输入的测试样例原始数据包装为JavaScript对象,后端服务器的服务程序捕获到输出的信息和用户捕获到数据结构的改变序列的输出信息均作为JavaScript对象中的值。As a further technical limitation, the back-end server obtains the programming language type information in the user's POST request, starts the API of the back-end server according to the programming language type information to create the corresponding Docker container, and the back-end server reads the POST during the process of creating the container. The running mode sent in the request, the code execution tag is stored in the database; the back-end server reads the user-defined code in the POST request, and injects the test sample input by the user as the original data of the data structure proxy class into the code file. , save the code file to the data volume created by the container for internal access to the container and execute the code; after the program runs, the change sequence of the algorithm data structure stored in the proxy class will be output, and the service program of the back-end server will be output. After capturing the output information, the user wraps the output information of the change sequence of the captured data structure and the original data of the test sample input by the user sent by the POST request into a JavaScript object, and the service program of the back-end server captures the output information and The user captures the output information of the sequence of changes to the data structure as the value in the JavaScript object.

作为进一步的技术限定,前端服务器从JSON数据种解析自定义代码种代理类数据结构的改变序列信息和原始数据,代理类数据结构的改变序列和原始数据的形式都为JavaScript数组;根据解析后的数据,使用JavaScript操作服务器中的DOM元素移动来生成动画。As a further technical limitation, the front-end server parses the change sequence information and original data of the proxy data structure of the custom code from the JSON data, and the change sequence and the original data of the proxy data structure are in the form of JavaScript arrays; according to the parsed data data, using JavaScript to manipulate the movement of DOM elements in the server to generate animations.

根据一些实施例,本公开的第二方案提供了一种基于代理模式和前后端分离的算法动画生成系统,采用如下技术方案:According to some embodiments, the second solution of the present disclosure provides an algorithm animation generation system based on proxy mode and front-end and back-end separation, and adopts the following technical solutions:

一种基于代理模式和前后端分离的算法动画生成系统,包括:An algorithm animation generation system based on proxy mode and separation of front and back ends, including:

前端服务器初始化模块,其被配置为通过前端服务器加载算法动画展示页面,将所述动画展示页面映射到预设位置;a front-end server initialization module, which is configured to load the algorithm animation display page through the front-end server, and map the animation display page to a preset position;

自定义代码模块,其被配置为基于代码所需信息在前端服务器中生成自定义代码,向后端服务器发起提交代码请求;A custom code module, which is configured to generate custom code in the front-end server based on the information required by the code, and initiate a code submission request to the back-end server;

后端服务器处理模块,其被配置为后端服务器接收到前端服务器所发起的提交代码请求,处理所接收到的代码,生成代码动画数据,将所生成的代码动画数据返回至前端服务器;A back-end server processing module, which is configured for the back-end server to receive a code submission request initiated by the front-end server, process the received code, generate code animation data, and return the generated code animation data to the front-end server;

算法动画生成模块,其被配置为前端服务器接收后端服务器所返回的代码动画数据,结合所映射的预设位置生成算法动画。The algorithm animation generation module is configured for the front-end server to receive the code animation data returned by the back-end server, and to generate the algorithm animation in combination with the mapped preset positions.

根据一些实施例,本公开的第三方案提供了一种计算机可读存储介质,采用如下技术方案:According to some embodiments, a third solution of the present disclosure provides a computer-readable storage medium, using the following technical solutions:

一种计算机可读存储介质,其上存储有程序,该程序被处理器执行时实现如本公开第一方面所述的基于代理模式和前后端分离的算法动画生成方法中的步骤。A computer-readable storage medium stores a program thereon, and when the program is executed by a processor, implements the steps in the algorithm animation generation method based on the agent mode and front-end and back-end separation according to the first aspect of the present disclosure.

根据一些实施例,本公开的第四方案提供了一种电子设备,采用如下技术方案:According to some embodiments, a fourth solution of the present disclosure provides an electronic device, using the following technical solutions:

一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的程序,所述处理器执行所述程序时实现如本公开第一方面所述的基于代理模式和前后端分离的算法动画生成方法中的步骤。An electronic device, comprising a memory, a processor and a program stored on the memory and executable on the processor, when the processor executes the program, the agent-based mode and front-end and back-end described in the first aspect of the present disclosure are implemented Steps in a separate algorithmic animation generation method.

与现有技术相比,本公开的有益效果为:Compared with the prior art, the beneficial effects of the present disclosure are:

本公开基于前后端分离的设计,提出一种使用代理模式的生成算法动画的方法;将代码中的数据结构的变化以动画的形式展示出来,形成代码程序所对应的完整的算法动画,前端服务器负责生成并展示动画,后端负责执行代码,前后端通过网络请求进行数据交互,分工明确,可维护性和可拓展性都很高。Based on the design of separation of front and back ends, the present disclosure proposes a method for generating algorithm animations using proxy mode; the changes in the data structure in the code are displayed in the form of animation to form a complete algorithm animation corresponding to the code program, and the front-end server It is responsible for generating and displaying animations, the back-end is responsible for executing code, and the front-end and back-end interact with data through network requests. The division of labor is clear, and the maintainability and scalability are high.

附图说明Description of drawings

构成本公开的一部分的说明书附图用来提供对本公开的进一步理解,本公开的示意性实施例及其说明用于解释本公开,并不构成对本公开的不当限定。The accompanying drawings that constitute a part of the present disclosure are used to provide further understanding of the present disclosure, and the exemplary embodiments of the present disclosure and their descriptions are used to explain the present disclosure and do not constitute an improper limitation of the present disclosure.

图1是本公开实施例一中的基于代理模式和前后端分离的算法动画生成方法的流程图;1 is a flowchart of an algorithm animation generation method based on proxy mode and front-end and back-end separation in Embodiment 1 of the present disclosure;

图2是本公开实施例一中的用户自定义代码阶段的流程图;2 is a flowchart of a user-defined code stage in Embodiment 1 of the present disclosure;

图3是本公开实施例一中的后端处理代码生成数据阶段的流程图;3 is a flowchart of a back-end processing code generation data stage in Embodiment 1 of the present disclosure;

图4是本公开实施例一中的自定义代码动画展示界面及算法动画的示意图;4 is a schematic diagram of a custom code animation display interface and algorithm animation in Embodiment 1 of the present disclosure;

图5是本公开实施例二中的基于代理模式和前后端分离的算法动画生成系统的结构框图。FIG. 5 is a structural block diagram of an algorithm animation generation system based on an agent mode and front-end and back-end separation in Embodiment 2 of the present disclosure.

具体实施方式Detailed ways

下面结合附图与实施例对本公开作进一步说明。The present disclosure will be further described below with reference to the accompanying drawings and embodiments.

应该指出,以下详细说明都是例示性的,旨在对本公开提供进一步的说明。除非另有指明,本文使用的所有技术和科学术语具有与本公开所属技术领域的普通技术人员通常理解的相同含义。It should be noted that the following detailed description is exemplary and intended to provide further explanation of the present disclosure. Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure belongs.

需要注意的是,这里所使用的术语仅是为了描述具体实施方式,而非意图限制根据本公开的示例性实施方式。如在这里所使用的,除非上下文另外明确指出,否则单数形式也意图包括复数形式,此外,还应当理解的是,当在本说明书中使用术语“包含”和/或“包括”时,其指明存在特征、步骤、操作、器件、组件和/或它们的组合。It should be noted that the terminology used herein is for the purpose of describing specific embodiments only, and is not intended to limit the exemplary embodiments according to the present disclosure. As used herein, unless the context clearly dictates otherwise, the singular is intended to include the plural as well, furthermore, it is to be understood that when the terms "comprising" and/or "including" are used in this specification, it indicates that There are features, steps, operations, devices, components and/or combinations thereof.

在不冲突的情况下,本公开中的实施例及实施例中的特征可以相互组合。The embodiments of this disclosure and features of the embodiments may be combined with each other without conflict.

实施例一Example 1

本公开实施例一介绍了一种基于代理模式和前后端分离的算法动画生成方法。Embodiment 1 of the present disclosure introduces an algorithm animation generation method based on a proxy mode and separation of front and back ends.

如图1所示的一种基于代理模式和前后端分离的算法动画生成方法,包括:As shown in Figure 1, an algorithm animation generation method based on proxy mode and separation of front and back ends, including:

前端初始化阶段:前端服务器初始化并加载算法动画展示页面,使用路由将各个页面组件映射到相应的位置;Front-end initialization stage: The front-end server initializes and loads the algorithm animation display page, and uses routing to map each page component to the corresponding position;

用户自定义代码阶段:用户选择运行模式、编程语言、设置代码执行标签、输入测试样例,编写自定义代码,向后端服务器发起提交代码请求;User-defined code stage: the user selects the running mode, programming language, sets the code execution label, enters test samples, writes custom code, and initiates a code submission request to the back-end server;

后端处理代码生成数据阶段:后端服务器收到前端发来的代码之后,处理代码,并返回生成具有约定格式的代码动画的数据;Back-end processing code generation data stage: After the back-end server receives the code from the front-end, it processes the code and returns the data that generates the code animation with the agreed format;

前端服务器生成算法动画阶段:前端服务器接收用于生成代码动画的数据,利用该数据生成算法动画。The front-end server generates the algorithm animation stage: the front-end server receives the data used to generate the code animation, and uses the data to generate the algorithm animation.

作为一种或多种实施方式,前端初始化阶段包括:前端服务器初始化并加载算法动画展示页面,使用路由将各个页面组件映射到相应的位置。As one or more implementation manners, the front-end initialization phase includes: the front-end server initializes and loads the algorithm animation display page, and uses routing to map each page component to the corresponding position.

具体的,前端服务器初始化并加载算法动画展示页面的过程中,前端服务器向Nginx服务器请求静态资源;前端服务器使用axios请求后端服务器的数据资源,即前端服务器请求后端数据资源的时候,先向Nginx服务器发起请求,Nginx服务器请求转发到后端对应的服务进行处理;前端Vue算法动画组件。Specifically, when the front-end server initializes and loads the algorithm animation display page, the front-end server requests static resources from the Nginx server; the front-end server uses axios to request the data resources of the back-end server, that is, when the front-end server requests the back-end data resources, it first requests The Nginx server initiates a request, and the Nginx server request is forwarded to the corresponding service in the back-end for processing; the front-end Vue algorithm animation component.

前端Vue算法动画组件具体包括:The front-end Vue algorithm animation components specifically include:

前端的算法动画组件是用来播放算法动画的Vue组件,该组件中包含一个canvas画布DOM元素,可以使用JavaScript在canvas元素所在的区域进行算法动画的绘制和生成。为了更加简单的进行算法动画的生成,可以将数组、树和图这三个数据结构的各种操作动画进行封装。进行分装后,前端在算法动画展示的时候只需要调用封装好的方法就可以生成动画的一帧,多个帧连续在一起就可以形成完整的算法动画了。对动画进行封装的底层原理就是操作canvas画布DOM元素进行绘制,最终生成动画。The front-end algorithm animation component is a Vue component used to play algorithm animation. The component contains a canvas DOM element, and JavaScript can be used to draw and generate algorithm animation in the area where the canvas element is located. In order to generate algorithm animations more simply, various operation animations of the three data structures of array, tree and graph can be encapsulated. After sub-packaging, the front-end only needs to call the encapsulated method to generate one frame of the animation when the algorithm animation is displayed, and multiple frames can be connected together to form a complete algorithm animation. The underlying principle of encapsulating animation is to manipulate canvas DOM elements to draw, and finally generate animation.

使用路由将各个页面组件映射到相应的位置的过程中,使用Vue框架中的路由插件Vue-Router来映射前端服务器所有页面;采用能够提高页面加载速度的路由懒加载的方式加载路由;前端将会使用Vue-Router插件,将按照Vue路由规则匹配页面中各个Vue组件,Vue路由规则也可以进行嵌套,十分灵活,使构建单页面应用变得轻而易举。路由懒加载可以使组件被需要的时候才进行加载,提高应用性能和用户使用体验。In the process of using routing to map each page component to the corresponding location, use the routing plug-in Vue-Router in the Vue framework to map all the pages of the front-end server; use the route that can improve the loading speed of the page to load the route in a lazy way; the front-end will Using the Vue-Router plug-in, each Vue component in the page will be matched according to the Vue routing rules. The Vue routing rules can also be nested, which is very flexible and makes it easy to build a single-page application. Routing lazy loading allows components to be loaded only when they are needed, improving application performance and user experience.

作为一种或多种实施方式,用户自定义代码阶段的流程图如图2所示,用户自定义代码时需要输入很多信息,并使用代理类来编写代码,具体流程如下:As one or more implementations, the flowchart of the user-defined code stage is shown in Figure 2. When the user defines the code, a lot of information needs to be input, and the proxy class is used to write the code. The specific process is as follows:

首先,用户输入提交代码所需的必要信息;First, the user enters the necessary information required to submit the code;

(1)用户选择运行模式(1) User selects the operating mode

运行模式分为三种,分别是数组、树和图。运行模式的选择取决于用户程序中的代理类的类型,如果代码中使用的是树代理类,最终生成的目标动画是树数据结构的算法动画,那么选择的运行模式也应当是树。There are three operating modes: array, tree and graph. The selection of the running mode depends on the type of the proxy class in the user program. If the tree proxy class is used in the code and the final target animation is the algorithm animation of the tree data structure, the selected running mode should also be the tree.

(2)用户选择编程语言(2) The user selects the programming language

用户可以使用不同编程语言来编写代码,算法动画支持Java、C++、Python。代码发送到后端服务器之后将会根据用户选择的编程语言来创建具有相应编程语言运行环境的Docker容器。Users can use different programming languages to write code, and algorithm animation supports Java, C++, Python. After the code is sent to the backend server, a Docker container with the corresponding programming language runtime environment will be created according to the programming language selected by the user.

(3)用户输入代码执行标签(3) The user enters the code to execute the label

该执行表执行标签用于简要描述一下代码中的算法,主要是用于标记,可以根据需求随意填写。The execution label of the execution table is used to briefly describe the algorithm in the code, mainly for marking, which can be filled in at will according to requirements.

(4)用户输入测试样例(4) User input test sample

用户的输入的测试样例将会用来初始化用户自定义代码中的数据结构的原始数据。The user input test case will be used to initialize the raw data of the data structure in the user-defined code.

其次,用户编写自定义代码;Second, the user writes custom code;

(1)构思算法,使用代理类编写代码(1) Conceive the algorithm and use the proxy class to write the code

用户首先要思考算法中所需要的数据结构,使用数组、树或者图代理类来实现算法。The user must first think about the data structure required in the algorithm, and implement the algorithm using an array, tree or graph proxy class.

(2)使用代理类提供的特定方法来修改数据(2) Use the specific methods provided by the proxy class to modify the data

这些方法可以将代理类中进行的操作,例如增加数据、修改数据等等以序列的形式记录并储存到内存中,程序结束的时候将这些信息全部输出。These methods can record and store the operations performed in the proxy class, such as adding data, modifying data, etc. in the form of a sequence, to the memory, and output all this information when the program ends.

下面列举了数组、树、图代理类中提供的方法:The methods provided in the array, tree, and graph proxy classes are listed below:

数组array

swap(index1,index2):交换数组中索引为index1和index2的元素。swap(index1,index2): Swap the elements at index1 and index2 in the array.

add(index,value):在数组索引为index的位置添加一个值为value的元素。add(index,value): Adds an element whose value is value at the position of index index in the array.

get(index):获取数组索引为index的元素。get(index): Get the element whose index is index in the array.

remove(index):删除数组索引为index的元素。remove(index): removes the element whose index is index in the array.

树(index为结点在完全二叉树中的位置,树不要求是完全二叉树,但是使用完全而二叉树的策略标记数中的元素位置)Tree (index is the position of the node in the complete binary tree, the tree is not required to be a complete binary tree, but the element position in the number of markers is marked using the strategy of the complete and binary tree)

get(index):获取树中位置为index的元素。get(index): Get the element at the position of index in the tree.

swap(index1,index2):交换树中位置为index1和index2的元素。swap(index1, index2): Swap the elements at positions index1 and index2 in the tree.

insert(index,value):在树中为index位置的空叶子结点上插入一个新的叶子结点,该叶子结点值为value。insert(index,value): Insert a new leaf node on the empty leaf node at the index position in the tree, and the value of the leaf node is value.

remove(index):在树中为index位置的叶子结点上删除该叶子结点。remove(index): Remove the leaf node from the leaf node at the index position in the tree.

picture

emp(index):将编号为index的图中节点,标记为强调状态。emp(index): Mark the node in the graph numbered index as the emphasis state.

unemp(index):将编号为index的图中节点,标记为非强调状态。unemp(index): Mark the node numbered as index in the unemphasized state.

link(index1,index2):将图中编号为index1和index2的两个图中节点所确定的边标记为强调状态。link(index1, index2): Marks the edge determined by the two graph nodes numbered index1 and index2 as the emphasized state.

unlink(index1,index2):将图中编号为index1和index2的两个图中节点所确定的边标记为非强调状态。unlink(index1,index2): Marks the edge determined by the nodes in the two graphs numbered index1 and index2 as the unemphasized state.

addPoint(position1,position2):为图中坐标为(position1,position2)的位置处添加一个点。addPoint(position1, position2): Add a point to the position where the coordinates are (position1, position2) in the figure.

addLine(position1,position2,position3,position4):为图中坐标为(position1,position2)和(position3,position4)点之间添加一条边。addLine(position1, position2, position3, position4): Add an edge between the points whose coordinates are (position1, position2) and (position3, position4) in the figure.

(3)向后端服务器发起提交代码请求(3) Initiate a code submission request to the back-end server

前端服务器将会发起POST请求,Nginx服务器将会请求转发到后端服务对应的控制器,之后服务器处理代码,返回生成动画所需要的动画数据。The front-end server will initiate a POST request, and the Nginx server will forward the request to the controller corresponding to the back-end service. After that, the server processes the code and returns the animation data needed to generate the animation.

作为一种或多种实施方式,后端处理代码生成数据阶段的流程图如图3所示,具体为:As one or more implementations, the flow chart of the data generation stage of the back-end processing code is shown in FIG. 3 , specifically:

首先,创建具有代码运行环境的Docker容器;First, create a Docker container with a code runtime environment;

后端服务器会先获取用户POST请求中的编程语言类型信息,根据这个编程语言信息启动后端服务的API来创建相应的Docker容器。后端服务器在创建容器的过程中也会读取POST请求中发来的运行模式,代码执行标签,存入数据库。The back-end server will first obtain the programming language type information in the user's POST request, and start the API of the back-end service according to the programming language information to create the corresponding Docker container. During the process of creating the container, the back-end server will also read the operation mode sent in the POST request, and the code execution tag will be stored in the database.

其次,将代码以文件的形式保存至容器创建的数据卷中,在容器中运行代码;Second, save the code in the form of a file to the data volume created by the container, and run the code in the container;

后端服务器会读取POST请求中的用户自定义代码,然后将用户输入的测试样例作为数据结构代理类的原始数据注入到代码文件之中,之后将代码文件保存至容器创建的数据卷中以供容器内部可以访问并执行代码。The back-end server will read the user-defined code in the POST request, and then inject the test sample entered by the user into the code file as the raw data of the data structure proxy class, and then save the code file to the data volume created by the container So that the container can access and execute code.

再次,程序运行结束后,获取生成代码动画的数据,并销毁容器;Once again, after the program runs, obtain the data for generating the code animation, and destroy the container;

程序运行结束后,代理类中存储的算法数据结构的改变序列将会被输出出来,代理类中算法数据结构的改变序列是用于生成算法动画的重要数据之一。后端服务器的服务程序会捕获到输出的信息。用户自定义的代码程序执行结束之后,就可以销毁docker容器,节省服务器的磁盘资源。After the program runs, the change sequence of the algorithm data structure stored in the proxy class will be output. The change sequence of the algorithm data structure in the proxy class is one of the important data for generating algorithm animation. The service program of the backend server will capture the output information. After the user-defined code program is executed, the docker container can be destroyed to save the disk resources of the server.

最后,后端服务器将生成代码动画的数据封装为JSON;Finally, the back-end server encapsulates the data for generating code animations as JSON;

用户将捕获到数据结构的改变序列的输出信息和POST请求发来的用户所输入的测试样例原始数据包装为JavaScript对象,两种信息均作为JavaScript对象中的值,两种信息所对应的键可以视情况约定,但必须保证前端浏览遵守该约定。The user wraps the output information of the change sequence of the captured data structure and the original data of the test sample input by the user sent by the POST request into a JavaScript object. It can be agreed according to the situation, but it must be ensured that the front-end browsing abides by the agreement.

作为一种或多种实施方式,前端服务器生成算法动画阶段的流程具体为:As one or more implementation manners, the flow of the front-end server generating the algorithm animation phase is as follows:

首先,将收到的JSON数据进行解析;First, parse the received JSON data;

前端从JSON数据种解析自定义代码种代理类数据结构的改变序列信息和原始数据。代理类数据结构的改变序列和原始数据的形式都为JavaScript数组。The front-end parses the change sequence information and original data of the proxy data structure of the custom code from the JSON data. Both the change sequence of the proxy class data structure and the original data are in the form of JavaScript arrays.

其次,根据解析好的数据,使用JavaScript操作服务器中的DOM元素移动来生成动画;Secondly, according to the parsed data, use JavaScript to manipulate the movement of DOM elements in the server to generate animations;

在生成动画的过程中,JavaScript操作的DOM对象是canvas画布元素。生成算法动画时,首先读取JSON解析出的原始数据,之后根据数据结构的类型使用JavaScript提供的API在canvas绘制数据结构在代码算法开始时的样子,之后根据JSON解析出的数据结构改变序列绘制动画的每一帧,每一帧之间都会添加动画过度效果,这样将动画的每一帧都连接起来播放就可以形成可供观看的算法动画。In the process of generating animation, the DOM object that JavaScript operates on is the canvas element. When generating an algorithm animation, first read the original data parsed by JSON, then use the API provided by JavaScript to draw the data structure on canvas according to the type of data structure at the beginning of the code algorithm, and then change the sequence drawing according to the data structure parsed by JSON Each frame of the animation and between each frame will add an animation transition effect, so that each frame of the animation is connected and played to form a watchable algorithm animation.

本实施例中的数据结构代理类的设计和服务器架构的设计,具体实现方案如下:The design of the data structure proxy class and the design of the server architecture in this embodiment, the specific implementation scheme is as follows:

后端部分back end part

1.数据结构代理类的设计1. Design of data structure proxy class

(1)数组代理类的设计实现(1) Design and implementation of array proxy class

现在以Java语言中的ArrayList的代理类为例来讨论一下代理类具体的实现思路和实现细节。首先编写一个类命名为ArrayList,在自定义的ArrayList中加入以下变量:一个java.util包下的ArrayList变量,变量名为arr、一个泛型为String类型的java.util.ArrayList变量,变量名为operations,之后在自定义的ArrayList中编写需要的方法,例如get方法、swap方法、add方法、remove方法,代理类的get、swap、add、remove方法是通过调用java.util包下的ArrayList变量中的方法来实现的,但在调用之前会向operations中写入所进行的操作,比如在程序的执行过程中交换了索引1和索引2位置上的元素,调用了方法swap(1,2),operations将会以字符串的形式记录下“swap(1,2)”。Now take the proxy class of ArrayList in Java language as an example to discuss the specific implementation ideas and implementation details of the proxy class. First write a class named ArrayList, and add the following variables to the custom ArrayList: an ArrayList variable under the java.util package, the variable name is arr, a java.util.ArrayList variable whose generic type is String, and the variable name is operations, and then write the required methods in a custom ArrayList, such as get method, swap method, add method, remove method, and get, swap, add, and remove methods of the proxy class by calling the ArrayList variable under the java.util package. However, the operations performed will be written into operations before the call, such as swapping the elements at index 1 and index 2 during the execution of the program, and calling the method swap(1,2), operations will log "swap(1,2)" as a string.

(2)树代理类的设计实现(2) Design and implementation of tree proxy class

可以看出记录类似于数组的数据结构的操作序列是相对简单的,如果想要记录树和图的操作序列,就需要寻找新的办法。It can be seen that it is relatively simple to record the operation sequence of the data structure similar to the array. If you want to record the operation sequence of the tree and graph, you need to find a new way.

关于树的动画,编写一个类BinaryTree,operations变量用于记录对树的操作。树的基本操作有插入、删除和交换和获取,在编写insert,remove,swap,get方法,调用这些方法的时候将操作写入operations中。记录这些操作需要找到一种方法准确地定位树中节点的位置,完全二叉树为提供了一个很好的思路。完全二叉树可以表示为一个数组的形式,数组的每一个索引可以定位一个树中的节点。假如某一个节点为空,就将对应索引位置置为一个特殊字符。假如树中索引位置为5的节点的左子节点为空,现在为其插入一个新的左子节点,节点的置为1,则会向operations变量中加入字符串“insert(10,1)”(完全二叉树中父节点的索引为n,左子节点对应的索引为2n,右子节点对应的索引为2n+1)。假如要交换索引为5的节点和其左子节点的位置则会向operations变量中加入字符串“swap(5,10)”。如果要删除索引为5的节点,(要求被删除的节点左右子树为空)则会向operations变量中加入字符串“remove(5)”。如果要获取索引为5的节点的值,则会向operations变量中加入字符串“get(5)”。Regarding the animation of the tree, write a class BinaryTree, and the operations variable is used to record the operations on the tree. The basic operations of the tree include insertion, deletion, exchange and acquisition. When writing the insert, remove, swap, and get methods, the operations are written into operations when these methods are called. Recording these operations requires finding a way to locate exactly where the nodes are in the tree, and a complete binary tree provides a good idea. A complete binary tree can be represented as an array, where each index of the array can locate a node in the tree. If a node is empty, set the corresponding index position to a special character. If the left child node of the node with index position 5 in the tree is empty, and now insert a new left child node for it, and the node's value is set to 1, the string "insert(10,1)" will be added to the operations variable. (The index of the parent node in the complete binary tree is n, the index corresponding to the left child node is 2n, and the index corresponding to the right child node is 2n+1). If you want to swap the position of the node with index 5 and its left child node, the string "swap(5,10)" will be added to the operations variable. If you want to delete the node with index 5, (the left and right subtrees of the deleted node are required to be empty), the string "remove(5)" will be added to the operations variable. To get the value of the node with index 5, the string "get(5)" is added to the operations variable.

(3)图代理类的设计实现(3) Design and implementation of graph proxy class

关于图的动画,约定所有的二维图均处在一个直角座坐标系中,图中的每一个点都可以用两个数字来表示这个点的坐标,图中的线可以用两个点的坐标来表示。根据以上的约束就可以记录图中任何一个点和线的改变,定义一个Graph类,含有operations变量用于记录对图的操作。假如在图中坐标为(1,2)的位置上添加一个点,则向operations变量中添加字符串“addPoint(1,2)”,如果要在坐标为(1,2)和坐标为(3,4)的点之间添加一条线段,则向operations变量中添加字符串“addLine(1,2,3,4)”,删除线段和删除点和前面的描述类似。Regarding the animation of the graph, it is agreed that all two-dimensional graphs are in a Cartesian coordinate system. Each point in the graph can use two numbers to represent the coordinates of this point, and the line in the graph can use the coordinates of the two points. coordinates to represent. According to the above constraints, the changes of any point and line in the graph can be recorded, and a Graph class is defined, which contains the operations variable to record the operations on the graph. If you add a point at the position where the coordinates are (1,2) in the figure, add the string "addPoint(1,2)" to the operations variable, if you want to add a point at the coordinates (1,2) and the coordinates (3) ,4) add a line segment between the points, then add the string "addLine(1,2,3,4)" to the operations variable, delete the line segment and delete the point similar to the previous description.

2.服务器的架构设计实现2. The architecture design and implementation of the server

(1)服务器执行实现(1) Server execution implementation

首先前端发送过来的请求首先会经过Nginx进行请求转发,Web端使用Vue打包好的dist文件夹也是Nginx所要处理的静态资源,后端收到前端发来的含有用户自定义的代码的请求后,将会在服务器上首先创建一个Data文件,并将前端发来的JSON数据中用户定义的原始数据写入Data文件,之后在创建一个代码文件,将用户的代码写入这个文件中,用户在提交代码的时候有一个限制是代码中的数据结构例如列表、二叉树等等必须是本产品提供的代理类,在代码执行的过程中对这些代理类对象的任何改变操作也必须使用代理类提供的方法,这些代理类中都拥有一个String类型的operations数组来记录这些类在程序中所做的所有操作,代理类也拥有将生成的Data文件中的数据自动注入的功能,代理类在初始化的时候就会将Data文件中的数据保存在类中,在程序运行结束的时候将会把operations和原始数据以JSON的格式输出到控制台上。服务器将请求中的代码和数据全部写入文件之后,假如用户提交的是Java代码,(用户可以提交不同的编程语言代码,后端可以根据编程语言的类型来使用Docker生成不同镜像的容器)这时服务器会使用根据Docker的openjdk镜像生成的一个容器,将上面生成的代码文件挂载到容器上,并在Docker容器中运行代码。如前面所说的,代码运行完会产生一个JSON字符串,这个JSON字符串记录着数据结构在程序中所进行的操作序列和原始数据信息,后端得到这个JSON字符串之后便将它返回给前端,前端根据这个JSON字符串中的操作序列来生成算法的动画在页面上展示。First of all, the request sent by the front end will be forwarded by Nginx first. The dist folder packaged by Vue on the web side is also the static resource to be processed by Nginx. After the back end receives the request containing the user-defined code from the front end, A Data file will be created first on the server, and the user-defined original data in the JSON data sent from the front end will be written into the Data file, and then a code file will be created, the user's code will be written into this file, and the user will submit There is a limitation in the code that the data structures in the code such as lists, binary trees, etc. must be the proxy classes provided by this product, and any changes to these proxy class objects during the code execution process must also use the methods provided by the proxy class. , these proxy classes have a String type operations array to record all the operations done by these classes in the program. The proxy class also has the function of automatically injecting the data in the generated Data file. The proxy class is initialized when it is initialized. The data in the Data file will be saved in the class, and operations and raw data will be output to the console in JSON format at the end of the program. After the server writes all the code and data in the request to the file, if the user submits Java code, (the user can submit different programming language codes, and the backend can use Docker to generate containers of different images according to the type of programming language) The server will use a container generated based on Docker's openjdk image, mount the code file generated above to the container, and run the code in the Docker container. As mentioned above, after the code runs, a JSON string will be generated. This JSON string records the sequence of operations performed by the data structure in the program and the original data information. After the backend gets the JSON string, it returns it to Front-end, the front-end generates an animation of the algorithm based on the sequence of operations in this JSON string and displays it on the page.

(2)服务器安全设计实现(2) Server security design and implementation

众所周知,让用户的代码上传到服务器来执行是有很大的安全隐患的,一些不怀好意的用户将会提交一些恶意代码,这些代码一旦执行就会给机器带来不可想象的灾难性后果,例如有的用户可以使用代码不断的发起CPU中断请求,使服务器卡死。还有的用户通过代码对服务器植入挖矿程序,这样的话服务器上正常运行的程序将会被挖矿程序抢占CPU资源,使服务器的功能彻底瘫痪。为了避免以上情况的发生,使用Docker来隔离代码运行环境和服务器本身的环境,在运行代码的时候,给正在运行代码的Docker容器只分配一个CPU,这样即使有恶意代码耗尽Docker所使用的CPU资源,也不会影响到Docker容器以外的服务器功能的使用,因为服务器的其他功能和Docker使用的完全是两个不同的CPU,它们之间不相互干扰,没用任何的直接联系。如果用户的代码在执行过程中导致Docker容器直接死机挂掉,这时服务器会删除掉令Docker容器死机的代码,重启Docker容器,重启Docker容器的过程中不允许已经提交到服务器的代码运行,必须等待Docker容器重启成功之后在依次运行,这样的设计使后端服务器具有一定的自我修复性。As we all know, uploading the user's code to the server for execution is a big security risk. Some malicious users will submit some malicious code, which will bring unimaginable catastrophic consequences to the machine once executed. For example, some users can use code to continuously initiate CPU interrupt requests, causing the server to freeze. Some users implant mining programs into the server through code, so that the programs running normally on the server will be preempted by the mining program for CPU resources, which will completely paralyze the functions of the server. In order to avoid the above situation, Docker is used to isolate the code running environment and the server's own environment. When running the code, only one CPU is allocated to the Docker container running the code, so that even if there is malicious code, the CPU used by Docker is exhausted. resources, and will not affect the use of server functions other than the Docker container, because other functions of the server and Docker use two different CPUs, which do not interfere with each other and do not use any direct connection. If the user's code causes the Docker container to crash and hang directly during the execution process, the server will delete the code that caused the Docker container to crash, restart the Docker container, and the code that has been submitted to the server is not allowed to run during the restart of the Docker container. After waiting for the Docker container to restart successfully, it will run in sequence. This design makes the backend server have a certain self-healing ability.

前端部分front end

3.提交自定义代码3. Submit custom code

(1)输入提交代码所需的必要信息以及编写自定义代码(1) Enter the necessary information required to submit the code and write custom code

前端使用Vue框架搭建,使用Vue来开发Web前端服务器的所有页面,页面会提供输入提交代码所需的必要信息的Vue输入组件和输入自定义代码的Vue输入组件。Vue组件都封装在一个单页面程序中,以便工程化开发。The front-end is built with the Vue framework, and Vue is used to develop all the pages of the web front-end server. The page will provide Vue input components for inputting the necessary information for submitting code and Vue input components for inputting custom code. Vue components are encapsulated in a single-page program for engineering development.

4.将代码发送给后端4. Send the code to the backend

前端使用axios发送HTTP请求,将用户提交的信息以及自定义代码封装在POST请求中发送给后端服务器。The front-end uses axios to send HTTP requests, and encapsulates the information submitted by the user and custom code in a POST request and sends it to the back-end server.

5.动画展示阶段5. Animation display stage

前端收到JSON字符串之后首先将其转化成JavaScript对象,根据键提取对象中的原始数据信息和数据结构的变化序列。前端对动画的生成进行了封装,封装的原理就是将Vue算法动画组件中的操作DOM元素canvas的代码进行模块化,模块化后对外提供一个名为mvns的JavaScript数组变量,只需要向mvns数组变量中添加对应的数据结构的改变就可以实现算法动画的逐帧播放,如图4所示,为树的中序遍历算法动画的逐帧播放展示。After the front end receives the JSON string, it first converts it into a JavaScript object, and extracts the original data information in the object and the sequence of changes in the data structure according to the key. The front-end encapsulates the generation of animation. The principle of encapsulation is to modularize the code that operates the DOM element canvas in the Vue algorithm animation component. After the modularization, a JavaScript array variable named mvns is provided to the outside world, and only the mvns array variable is required. By adding the corresponding data structure changes in the algorithm, the frame-by-frame playback of the algorithm animation can be realized, as shown in Figure 4, which is the frame-by-frame playback display of the in-order traversal algorithm animation of the tree.

本实施例实现了基于代理模式的数据结构代理类,可在程序运行结束后输出数据结构的改变序列;实现了基于Docker的服务器安全架构;封装了前端算法动画的生成操作,形成简单易用的算法动画逐帧播放方式;实现了前后端分离的交互式算法动画展示。This embodiment implements the data structure proxy class based on the proxy mode, which can output the change sequence of the data structure after the program runs; implements the server security architecture based on Docker; encapsulates the generation operation of the front-end algorithm animation, forming an easy-to-use and easy-to-use Algorithmic animation is played frame by frame; the interactive algorithm animation display with front and back ends is realized.

实施例二Embodiment 2

本公开实施例二介绍了一种基于代理模式和前后端分离的算法动画生成系统。The second embodiment of the present disclosure introduces an algorithm animation generation system based on the proxy mode and the separation of front and back ends.

如图5所示的一种基于代理模式和前后端分离的算法动画生成系统,包括:As shown in Figure 5, an algorithm animation generation system based on the proxy mode and the separation of front and back ends, including:

前端服务器初始化模块,其被配置为通过前端服务器加载算法动画展示页面,将所述动画展示页面映射到预设位置;a front-end server initialization module, which is configured to load the algorithm animation display page through the front-end server, and map the animation display page to a preset position;

自定义代码模块,其被配置为基于代码所需信息在前端服务器中生成自定义代码,向后端服务器发起提交代码请求;A custom code module, which is configured to generate custom code in the front-end server based on the information required by the code, and initiate a code submission request to the back-end server;

后端服务器处理模块,其被配置为后端服务器接收到前端服务器所发起的提交代码请求,处理所接收到的代码,生成代码动画数据,将所生成的代码动画数据返回至前端服务器;a back-end server processing module, which is configured for the back-end server to receive a code submission request initiated by the front-end server, process the received code, generate code animation data, and return the generated code animation data to the front-end server;

算法动画生成模块,其被配置为前端服务器接收后端服务器所返回的代码动画数据,结合所映射的预设位置生成算法动画。The algorithm animation generation module is configured for the front-end server to receive the code animation data returned by the back-end server, and to generate the algorithm animation in combination with the mapped preset positions.

详细步骤与实施例一提供的基于代理模式和前后端分离的算法动画生成方法相同,在此不再赘述。The detailed steps are the same as the algorithm animation generation method based on the proxy mode and front-end and back-end separation provided in the first embodiment, and are not repeated here.

实施例三Embodiment 3

本公开实施例三提供了一种计算机可读存储介质。The third embodiment of the present disclosure provides a computer-readable storage medium.

一种计算机可读存储介质,其上存储有程序,该程序被处理器执行时实现如本公开实施例一所述的基于代理模式和前后端分离的算法动画生成方法中的步骤。A computer-readable storage medium stores a program thereon, and when the program is executed by a processor, implements the steps in the algorithm animation generation method based on the agent mode and front-end and back-end separation according to the first embodiment of the present disclosure.

详细步骤与实施例一提供的基于代理模式和前后端分离的算法动画生成方法相同,在此不再赘述。The detailed steps are the same as the algorithm animation generation method based on the proxy mode and front-end and back-end separation provided in the first embodiment, and are not repeated here.

实施例四Embodiment 4

本公开实施例四提供了一种电子设备。The fourth embodiment of the present disclosure provides an electronic device.

一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的程序,所述处理器执行所述程序时实现如本公开实施例一所述的基于代理模式和前后端分离的算法动画生成方法中的步骤。An electronic device, comprising a memory, a processor, and a program stored in the memory and running on the processor, when the processor executes the program, the agent-based mode and front-end and back-end described in Embodiment 1 of the present disclosure are implemented Steps in a separate algorithmic animation generation method.

详细步骤与实施例一提供的基于代理模式和前后端分离的算法动画生成方法相同,在此不再赘述。The detailed steps are the same as the algorithm animation generation method based on the proxy mode and front-end and back-end separation provided in the first embodiment, and are not repeated here.

以上所述仅为本公开的优选实施例而已,并不用于限制本公开,对于本领域的技术人员来说,本公开可以有各种更改和变化。凡在本公开的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本公开的保护范围之内。The above descriptions are only preferred embodiments of the present disclosure, and are not intended to limit the present disclosure. For those skilled in the art, the present disclosure may have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present disclosure should be included within the protection scope of the present disclosure.

Claims (10)

1.一种基于代理模式和前后端分离的算法动画生成方法,其特征在于,包括:1. a kind of algorithm animation generation method based on proxy mode and front-end and back-end separation, is characterized in that, comprises: 通过前端服务器加载算法动画展示页面,将所述动画展示页面映射到预设位置;Load the algorithm animation display page through the front-end server, and map the animation display page to a preset position; 基于代码所需信息在前端服务器中生成自定义代码,向后端服务器发起提交代码请求;Generate custom code in the front-end server based on the information required by the code, and initiate a code submission request to the back-end server; 后端服务器接收到前端服务器所发起的提交代码请求,处理所接收到的代码,生成代码动画数据,将所生成的代码动画数据返回至前端服务器;The back-end server receives the code submission request initiated by the front-end server, processes the received code, generates code animation data, and returns the generated code animation data to the front-end server; 前端服务器接收后端服务器所返回的代码动画数据,结合所映射的预设位置生成算法动画。The front-end server receives the code animation data returned by the back-end server, and generates algorithm animation in combination with the mapped preset positions. 2.如权利要求1中所述的一种基于代理模式和前后端分离的算法动画生成方法,其特征在于,在加载算法动画展示页面之前,前端服务器进行初始化,具体为:前端服务器向Nginx服务器请求静态资源,使用axios请求后端服务器的数据资源,在前端服务器请求后端数据资源的时候,先向Nginx服务器发起请求,Nginx服务器请求转发到对应的后端服务器中进行处理。2. a kind of algorithm animation generation method based on proxy mode and front and back end separation as described in claim 1, it is characterized in that, before loading algorithm animation display page, front-end server initializes, is specially: front-end server to Nginx server To request static resources, use axios to request the data resources of the back-end server. When the front-end server requests the back-end data resources, it first initiates a request to the Nginx server, and the Nginx server request is forwarded to the corresponding back-end server for processing. 3.如权利要求1中所述的一种基于代理模式和前后端分离的算法动画生成方法,其特征在于,在加载算法动画展示页面的过程中,通过前端服务器的算法动画组件播放算法动画的Vue组件,所述Vue组件采用含canvas画布的DOM元素,通过JavaScript在含canvas画布的DOM元素所在的区域进行算法动画的绘制和生成。3. a kind of algorithm animation generation method based on proxy pattern and front-end and back-end separation as described in claim 1, it is characterized in that, in the process of loading algorithm animation display page, by the algorithm animation component of front-end server playing algorithm animation A Vue component, the Vue component adopts a DOM element containing a canvas, and uses JavaScript to draw and generate an algorithmic animation in the area where the DOM element containing the canvas is located. 4.如权利要求3中所述的一种基于代理模式和前后端分离的算法动画生成方法,其特征在于,在将所述动画展示页面映射到预设位置的过程中,采用路由将各个动画展示页面组件映射到相应的位置,即使用所述Vue组件框架中的路由插件Vue-Router来映射前端服务器中所加载生成的算法动画展示页面,按照Vue路由规则进行算法动画展示页面各个Vue组件的匹配,将算法动画展示页面映射到相匹配的预设位置。4. a kind of algorithm animation generation method based on proxy mode and front-end separation as claimed in claim 3, is characterized in that, in the process that described animation display page is mapped to preset position, adopts route to each animation The display page components are mapped to the corresponding positions, that is, the routing plug-in Vue-Router in the Vue component framework is used to map the algorithm animation display page loaded and generated in the front-end server, and the algorithm animation display page is performed according to the Vue routing rules. Match, map the algorithm animation display page to the matching preset position. 5.如权利要求1中所述的一种基于代理模式和前后端分离的算法动画生成方法,其特征在于,用户选择运行模式、编程语言、设置代码执行标签和输入测试样例,编写自定义代码;前端服务器发起POST请求,Nginx服务器将请求转发到后端服务器所对应的控制器中,向后端服务器发起提交代码请求。5. a kind of algorithm animation generation method based on proxy pattern and front and back end separation as described in claim 1, it is characterized in that, user selects running pattern, programming language, sets code execution label and input test sample, writes self-defining Code; the front-end server initiates a POST request, the Nginx server forwards the request to the controller corresponding to the back-end server, and initiates a code submission request to the back-end server. 6.如权利要求1中所述的一种基于代理模式和前后端分离的算法动画生成方法,其特征在于,后端服务器获取用户POST请求中的编程语言类型信息,根据编程语言类型信息启动后端服务器的API来创建相应的Docker容器,后端服务器在创建容器的过程中读取POST请求中发来的运行模式,代码执行标签,存入数据库;后端服务器读取POST请求中的用户自定义代码,将用户输入的测试样例作为数据结构代理类的原始数据注入到代码文件之中,将代码文件保存至容器创建的数据卷中以供容器内部访问并执行代码;程序运行结束后,代理类中存储的算法数据结构的改变序列将会被输出出来,后端服务器的服务程序捕获到输出的信息,用户将捕获到数据结构的改变序列的输出信息和POST请求发来的用户所输入的测试样例原始数据包装为JavaScript对象,后端服务器的服务程序捕获到输出的信息和用户捕获到数据结构的改变序列的输出信息均作为JavaScript对象中的值。6. a kind of algorithm animation generation method based on proxy mode and front-end separation as claimed in claim 1, it is characterised in that the back-end server obtains the programming language type information in the user POST request, after starting according to the programming language type information The API of the end server is used to create the corresponding Docker container. During the process of creating the container, the back-end server reads the running mode sent in the POST request, executes the code and stores it in the database; Define the code, inject the test sample input by the user as the original data of the data structure proxy class into the code file, and save the code file to the data volume created by the container for internal access and execution of the code in the container; after the program runs, The change sequence of the algorithm data structure stored in the proxy class will be output, the service program of the back-end server will capture the output information, and the user will capture the output information of the data structure change sequence and the user input sent by the POST request. The original data of the test sample is packaged as a JavaScript object, and the output information captured by the service program of the back-end server and the output information captured by the user of the change sequence of the data structure are regarded as the value in the JavaScript object. 7.如权利要求1中所述的一种基于代理模式和前后端分离的算法动画生成方法,其特征在于,前端服务器从JSON数据种解析自定义代码种代理类数据结构的改变序列信息和原始数据,代理类数据结构的改变序列和原始数据的形式都为JavaScript数组;根据解析后的数据,使用JavaScript操作服务器中的DOM元素移动来生成动画。7. a kind of algorithm animation generation method based on proxy pattern and front-end separation as described in claim 1, is characterized in that, front-end server parses the change sequence information and the original data structure of self-defined code kind from JSON data kind of proxy data structure. The data, the change sequence of the proxy data structure and the original data are all in the form of JavaScript arrays; according to the parsed data, JavaScript is used to manipulate the movement of DOM elements in the server to generate animations. 8.一种基于代理模式和前后端分离的算法动画生成系统,其特征在于,包括:8. An algorithm animation generation system based on proxy mode and front-end and back-end separation, is characterized in that, comprises: 前端服务器初始化模块,其被配置为通过前端服务器加载算法动画展示页面,将所述动画展示页面映射到预设位置;a front-end server initialization module, which is configured to load the algorithm animation display page through the front-end server, and map the animation display page to a preset position; 自定义代码模块,其被配置为基于代码所需信息在前端服务器中生成自定义代码,向后端服务器发起提交代码请求;A custom code module, which is configured to generate custom code in the front-end server based on the information required by the code, and initiate a code submission request to the back-end server; 后端服务器处理模块,其被配置为后端服务器接收到前端服务器所发起的提交代码请求,处理所接收到的代码,生成代码动画数据,将所生成的代码动画数据返回至前端服务器;a back-end server processing module, which is configured for the back-end server to receive a code submission request initiated by the front-end server, process the received code, generate code animation data, and return the generated code animation data to the front-end server; 算法动画生成模块,其被配置为前端服务器接收后端服务器所返回的代码动画数据,结合所映射的预设位置生成算法动画。The algorithm animation generation module is configured for the front-end server to receive the code animation data returned by the back-end server, and to generate the algorithm animation in combination with the mapped preset positions. 9.一种计算机可读存储介质,其上存储有程序,其特征在于,该程序被处理器执行时实现如权利要求1-7中任一项所述的基于代理模式和前后端分离的算法动画生成方法中的步骤。9. A computer-readable storage medium on which a program is stored, characterized in that, when the program is executed by a processor, the algorithm based on proxy mode and front-end and back-end separation according to any one of claims 1-7 is implemented Steps in the animation generation method. 10.一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的程序,其特征在于,所述处理器执行所述程序时实现如权利要求1-7中任一项所述的基于代理模式和前后端分离的算法动画生成方法中的步骤。10. An electronic device comprising a memory, a processor and a program stored in the memory and running on the processor, wherein the processor implements any one of claims 1-7 when executing the program The steps in the algorithm animation generation method based on proxy mode and front-end and back-end separation described in item.
CN202210492780.0A 2022-05-07 2022-05-07 Algorithmic animation generation method and system based on proxy mode and front-end and back-end separation Pending CN114791803A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210492780.0A CN114791803A (en) 2022-05-07 2022-05-07 Algorithmic animation generation method and system based on proxy mode and front-end and back-end separation

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210492780.0A CN114791803A (en) 2022-05-07 2022-05-07 Algorithmic animation generation method and system based on proxy mode and front-end and back-end separation

Publications (1)

Publication Number Publication Date
CN114791803A true CN114791803A (en) 2022-07-26

Family

ID=82462426

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210492780.0A Pending CN114791803A (en) 2022-05-07 2022-05-07 Algorithmic animation generation method and system based on proxy mode and front-end and back-end separation

Country Status (1)

Country Link
CN (1) CN114791803A (en)

Similar Documents

Publication Publication Date Title
TWI808393B (en) Page processing method, device, apparatus and storage medium
CN111045655B (en) Page rendering method and device, rendering server and storage medium
Quigley et al. Programming Robots with ROS: a practical introduction to the Robot Operating System
CN110908712A (en) Data processing method and equipment for cross-platform mobile terminal
CN113703893B (en) Page rendering method, device, terminal and storage medium
US9632987B2 (en) Technique that enhances the manipulation of an HTML tree presentation by using an array representation of the hierarchical path of a tree node
JPH1124980A (en) Device and method for managing medium accessing plural medium types
WO2019238145A1 (en) Webgl-based graphics rendering method, apparatus and system
CN106991096A (en) Dynamic page rendering intent and device
CN110532495A (en) A kind of methods of exhibiting and device of webpage information
CN112755534B (en) Data processing method, device and storage medium
Ballamudi et al. Getting Started Modern Web Development with Next. js: An Indispensable React Framework
CN115131470A (en) A kind of graphic material synthesis method, device, electronic device and storage medium
CN116521181B (en) Script data processing method, device, equipment and medium based on game system
CN114791803A (en) Algorithmic animation generation method and system based on proxy mode and front-end and back-end separation
JP7344256B2 (en) Rendering methods, devices, electronic equipment and computer programs
CN116483240A (en) Method and device for realizing space data occupying view based on list and electronic equipment
CN116400914A (en) Method for quickly constructing web application based on data model
CN114090666A (en) Slide display method, apparatus, device and storage medium
CN111522546B (en) Page generation method, related device and front-end page
US20250013707A1 (en) Sub-application page processing method and apparatus, computer device, and storage medium
CN119105811A (en) Application startup method, device, computer equipment and storage medium
CN113434149B (en) Application program generating and loading method, device and medium
CN116595284B (en) Webpage system operation method, device, equipment, storage medium and program
CN116991506B (en) Webpage rendering method and device, terminal and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination