eureka2 / G6K

Generator of calculation simulator (calculator)
MIT License
20 stars 20 forks source link

How to use simulator as API #5

Closed ArfaouiHamouda closed 6 years ago

ArfaouiHamouda commented 6 years ago

Hi , i want to use the simulator as API to be implemented in an externel website , i have added the following lines to the "EUREKA\G6KBundle\Resources\ config\parameters.yml" file .

     api:
         mysimulator:
             step: 2
             action: calculate

my simulator works fine , as i have understood from the reading the code and the previous issue the api should run on : /calcul/mysimulator/api but cause of luck of Symfony knowledge i didn't know how to pass the arguments and as POST or GET Request , Thanks

eureka2 commented 6 years ago

Hi,

The GET or POST parameters are the name of the data that are in the input fields of the step.

For example, if you look at step 1 in the demo.xml file, look for the input fields: image then look for the name of the corresponding data : image Thus, income, AARight and nChildren are the arguments of the API

To verify this, add the following lines in the file "EUREKA\G6KBundle\Resources\config\parameters.yml"

    api:
        demo:
            step: 1
            action: calculate

then clear the cache

with this request : /calcul/demo/api?income=2000&AARight=2&nChildren=2 you get (with firefox): image

ArfaouiHamouda commented 6 years ago

i have understood the Demo Example and that API Works Good , actually i have imported some Data from an External API to i Which contain different types of Calculation , i Only need 4 Types of Calculations , but i can't figure out What Step to use , or even what steps refer to . Could you help me to implement this API and Understand more the Functionality of your Code .

eureka2 commented 6 years ago

Hi,

You must locate the step that contains the button that triggers the display of the results. In your case it's the step 0 and the "calculer" button

The arguments to provide to the API request are the data name / value pairs that are requested from the user (usage = "input") at this step and the previous steps.

NOTE: I do not provide help for simulators developed by third parties.

sdjeffal commented 5 years ago

Hi,

I don't found the file EUREKA\G6KBundle\Resources\ config\parameters.yml for use simulator as API webservice, still exists ? can you help me please. thank you ;)

eureka2 commented 5 years ago

Hi,

Which version did you install?

sdjeffal commented 5 years ago

I install the symfony 4.2

sdjeffal commented 5 years ago

For me, the routes API are already declared in file {project_dir}/{simulator}/config/routes/g6k.yaml but don't work.

When I make a request API:

GET http://localhost/calcul/cout-certificat-immatriculation/api?demarche=1&franceOuImport=1&typeVehicule=1&declareVehiculeDemonstration=2&puissanceAdministrative=52&energie=1&invalidite=2&receptionCommunautaire=1&tauxCO2=350&departement=92&declareVehiculeDeCollection=2

i have this response :

{
    "links": {
        "self": "http://g6k.local/calcul/cout-certificat-immatriculation/api?"
    },
    "errors": [
        {
            "status": "422",
            "title": "Unprocessable entity",
            "detail": "API for this simulator is not implemented",
            "source": {
                "pointer": "/data/"
            }
        }
    ]
}
eureka2 commented 5 years ago

the api must be declared in {project_dir}/{simulator}/config/packages/g6k.yaml

sdjeffal commented 5 years ago

it works, Thank you very much for your help

sdjeffal commented 5 years ago

the request api don't work with the mode 'prod'. Why ?

sdjeffal commented 5 years ago

I found a solution but i don't know if it is good. i copy the file {project_dir}/{simulator}/config/packages/dev/routing.yaml in {project_dir}/{simulator}/config/packages/prod/

eureka2 commented 5 years ago

You do not have to copy the file {project_dir}/{simulator}/config/packages/dev/routing.yaml

When you switch from dev to prod, you must clear all files in the {project_dir}/{simulator}/var/directory

I just did it and the API is working properly.

The response time is 5000ms for the first request because symfony must (re)generate the cache. It is 400ms for the following queries.

I am using version 4.2.16 of G6K and php 7.1.3! And you ?

sdjeffal commented 5 years ago

I used version master-dev of g6k with PHP 7.2.10. I installed the version 4.2.16 when you switch from dev to prod, API is working. But At each request the response time is 5000ms as if the cache system is not working

eureka2 commented 5 years ago

I don't have such a response time, so I don't know how to help you, sorry!

kiady66 commented 3 years ago

it works, Thank you very much for your help

@sdjeffal did you just put Capture d’écran de 2021-02-23 11-30-35

in {project_dir}/{simulator}/config/packages/g6k.yaml and it's worked? Or you did something else?

cause mine always says :

"API for this simulator is not implemented"

rayenhidri27 commented 3 years ago

i try to use your application, but when i publish the simulator, i have an xml error erreur G6K

im running sf 4.4.25 php 7.4 local env : wamp 3.2

also i wanna know what i must do after publishing the simulator to use it (it's not mentioned in the doc, it'll be nice if u add it)

kiady66 commented 3 years ago

@rayenhidri27 you are not in the right issue but in your case just take the xml that they put in their repo and follow the errors

rayenhidri27 commented 3 years ago

thx for your answer, i just want to know : 1- when i open the xml file, which lines can i modifiy and why im having this error 2- even if i correct the errors, how can i use the simulator ( specially as an API )?

it's not clear in the doc how to use it after that

kiady66 commented 3 years ago

I don't know in your case, but in my case when i imported the xml, some attributes was not allowed so i just remove them. and it works. To use it as an API, I just followed what they said above

rayenhidri27 commented 3 years ago

do u have a discord account ? or any mean of communication, so we can talk there in the errors, they mention that there is errors in tags, not just some attributes

eureka2 commented 3 years ago

Hi,

@rayenhidri27 You cannot publish a simulator if it contains errors or if it is not completely finalized. In your case, you have to go to the administration panel, open the simulator and add the missing elements, namely fieldsets in panels, chapters and sections in information blocks and fields in fieldsets. Once you have done this, the button "Try it" (or "tester" in French) appears in the toolbar. The url to use in production is the one displayed in your browser's address bar during testing without the word "tryIt".

kiady66 commented 3 years ago

Hi @eureka2, I implemented your simulator in the company that I am working for. when we make one request, it creates infinite of php-fpm thread. the ticket has not been solved for months, there is an infinite loop. the infinite request is GET /404.html. How do you think i can solve this fe

rayenhidri27 commented 3 years ago

i'm trying to fill the data, even the optional ones when i arrive to data step (donnees), i fill all needed information, and then when i save, i get this error as u see below erreur-donnees

would make short video for demo and put it on the readme file ?

it will be so helpfull for every one using this project

eureka2 commented 3 years ago

it looks like your simulator xml file is inconsistent, did you manually edit it at some point?

Go to C:\Users\rayen\Desktop\projets\sim2\simulator and run php bin/console g6k:simulator:validate -w sim4 and php bin/console g6k:simulator:validate sim4

rayenhidri27 commented 3 years ago

no, i didn't change it manually it's bloqued when i add data to simulator

do u have a discord account ? or any mean of communication, so we can talk there

would u make a short video for demo and put it on the readme file ? it will be so helpfull for every one using this project