-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphPhasePlane.php
More file actions
59 lines (47 loc) · 1.71 KB
/
GraphPhasePlane.php
File metadata and controls
59 lines (47 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Process;
class GraphPhasePlane extends Controller
{
public function __invoke(Request $request)
{
$START = hrtime(as_number: true);
$id = str()->random();
$body = $request->validate([
'equation1' => 'required|string',
'equation2' => 'required|string',
'xMin' => 'required|numeric',
'xMax' => 'required|numeric',
'yMin' => 'required|numeric',
'yMax' => 'required|numeric',
'tMax' => 'required|numeric|min:0|max:150',
'points' => 'present|array',
]);
$WORKING_DIR = resource_path('python');
$payload = [
...$body,
'destination' => "public/{$id}.png",
'xt_destination' => "public/{$id}_1.png",
'yt_destination' => "public/{$id}_2.png",
];
$encodedPayload = json_encode($payload);
$result = Process::path($WORKING_DIR)
->run("./venv/bin/python3 phase-plane.py '{$encodedPayload}'");
if ($result->failed()) {
posthog_event('graph_render_error', [
...$body,
'error' => $result->errorOutput(),
'time_elapsed' => round((hrtime(as_number: true) - $START) / 1e6),
'type' => '2d',
]);
return redirect()->back()->with('error', $result->errorOutput());
}
posthog_event('graph_rendered', [
...$body,
'time_elapsed' => round((hrtime(as_number: true) - $START) / 1e6),
'type' => '2d',
]);
return redirect()->back()->with('graph_id', $id);
}
}