Skip to content

Commit 139b2af

Browse files
PL-666ulysses4ever
authored andcommitted
uploaded movie review microservice benchmark
1 parent a04e531 commit 139b2af

File tree

13 files changed

+923
-0
lines changed

13 files changed

+923
-0
lines changed

gibbon-compiler/examples/movie/Basics.hs

Lines changed: 427 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module GenerateMovieLayout where
2+
import Movies
3+
4+
5+
gibbon_main =
6+
let
7+
test = mkMovieContent 'a'
8+
_ = printPacked test
9+
in ()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# modified based on clean.py from blog management
2+
import os
3+
import subprocess
4+
5+
gibbon_file_names = ["test","testInsertmovie", "testSearchMovie", "testDeleteMovie"]
6+
7+
# layouts = ["layout1", "layout2", "layout3", "layout4", "layout5", "layout6", "layout7", "layout8"]
8+
9+
print("Cleaning out the c files and binaries")
10+
11+
#Compilation phase
12+
for file_name in gibbon_file_names:
13+
14+
filename_c = file_name + ".c"
15+
filename_exe = file_name + ".exe"
16+
gibbon_cmd_c = subprocess.run(["rm", filename_c])
17+
gibbon_cmd_bin = subprocess.run(["rm", filename_exe])
18+
gibbon_cmd_bin = subprocess.run(["rm", file_name])
19+
20+
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
module Movies where
2+
-- import Data.Map
3+
import Gibbon.Prelude
4+
import Gibbon.PList
5+
import Gibbon.Vector
6+
import Gibbon.Maybe
7+
import Basics
8+
--
9+
type Text = Vector Char
10+
--
11+
type IsMovie = Bool
12+
type MovieTitle = Text
13+
type ReleaseDate = Text
14+
type Director = Text
15+
type Writers = PList Text
16+
type CastInfo = PList Text
17+
type MovieTags = PList Text
18+
type Rating = Int
19+
20+
-- --if IsMovie == True, the maybe values will exist
21+
data Movie = Empty
22+
| Movie MovieTitle
23+
ReleaseDate Director Writers CastInfo
24+
MovieTags Rating
25+
26+
data MovieTrie = Root
27+
| MovieTrie (Maybe Char) (Maybe IsMovie) (Maybe Movie) (Maybe (PList MovieTrie)) deriving (Show)
28+
29+
-- intToVec :: Int -> (Vector Int)
30+
-- intToVec i = let
31+
-- remainder = mod i 10
32+
-- quotient = div i 10
33+
-- in if(quotient == 0) then singleton remainder
34+
-- else append (intToVec quotient) (singleton remainder)
35+
-- intToChar :: Int -> Char
36+
-- intToChar i = case i of
37+
-- 0 -> '0'
38+
-- 1 -> '1'
39+
-- 2 -> '2'
40+
-- 3 -> '3'
41+
-- 4 -> '4'
42+
-- 5 -> '5'
43+
-- 6 -> '6'
44+
-- 7 -> '7'
45+
-- 8 -> '8'
46+
-- 9 -> '9'
47+
-- intToText :: (Vector Int) -> Text
48+
-- intToText i = if (length i == 1) then
49+
-- movieToText :: Movie -> Text
50+
-- movieToText m = case m of
51+
-- Empty -> "empty Movie"
52+
-- Movie c title date director wrriters castinfo movietags rating ->
53+
mkMovieContent :: Text -> Movie
54+
mkMovieContent t =
55+
let
56+
movietitle = t
57+
rdate = (getRandomString 5)
58+
director = (getRandomString 6)
59+
writer = Cons (getRandomString 5) Nil
60+
cast = Cons (getRandomString 5) Nil
61+
movietag = Cons (getRandomString 5) Nil
62+
rating = 5
63+
in Movie movietitle rdate director writer cast movietag rating
64+
65+
--insert a movie into movieTrie
66+
insertMovie :: Text -> (Maybe Char) -> Movie -> MovieTrie -> MovieTrie
67+
insertMovie t c m mt =
68+
if (length t == 0)
69+
then case mt of
70+
Root -> MovieTrie c (Just True) (Just m) Nothing
71+
MovieTrie c ismovie movie cmovieTrie -> MovieTrie c (Just True) (Just m) cmovieTrie
72+
else
73+
case mt of
74+
Root -> MovieTrie c (Just False) Nothing (Just (Cons (insertMovie (tail t) (Just (head t)) m Root) Nil))
75+
MovieTrie c ismovie movie cmovieTrie -> MovieTrie c ismovie movie (Just (insert_Mhelper t m (fromMaybe Nil cmovieTrie)))
76+
77+
movieGetChar :: MovieTrie -> Maybe Char
78+
movieGetChar mt = case mt of
79+
Root -> Nothing
80+
-- let _ = printsym (quote "nothing")
81+
-- in Nothing
82+
MovieTrie c ismovie movie lmt -> c
83+
-- let _ = printchar (fromMaybe ' ' c)
84+
-- in c
85+
86+
insert_Mhelper :: Text -> Movie -> (PList MovieTrie) -> (PList MovieTrie)
87+
insert_Mhelper t m lmt =
88+
case lmt of
89+
Nil -> Cons (insertMovie (tail t) (Just (head t)) m Root) Nil
90+
Cons x xs -> if (fromMaybe ' ' (movieGetChar x)) *==* head t then Cons (insertMovie (tail t) (Just (head t)) m x) xs
91+
else Cons x (insert_Mhelper t m xs)
92+
93+
deleteMovie :: Text -> MovieTrie -> MovieTrie
94+
deleteMovie t mt =
95+
if (length t == 0)
96+
then case mt of
97+
Root -> mt
98+
MovieTrie c ismovie movie cmovieTrie -> if (fromMaybe False ismovie) then MovieTrie c (Just False) (Nothing) cmovieTrie
99+
else MovieTrie c ismovie movie cmovieTrie
100+
else
101+
case mt of
102+
Root -> Root
103+
MovieTrie c ismovie movie cmovieTrie -> MovieTrie c ismovie movie (Just (delete_Mhelper t (fromMaybe Nil cmovieTrie)))
104+
105+
106+
delete_Mhelper :: Text -> (PList MovieTrie) -> (PList MovieTrie)
107+
delete_Mhelper t lmt =
108+
case lmt of
109+
Nil -> Nil
110+
Cons x xs -> if(fromMaybe ' ' (movieGetChar x)) *==* head t then Cons (deleteMovie (tail t) x) xs
111+
else Cons x (delete_Mhelper t xs)
112+
--given movietitle, find movie return empty if not found
113+
searchMovieTitle :: Text -> MovieTrie -> Movie
114+
searchMovieTitle t mt =
115+
if (length t == 0) then case mt of
116+
Root -> Empty
117+
MovieTrie c ismovie movie cmovieTrie -> if (fromMaybe False ismovie) then (fromMaybe Empty movie) else Empty
118+
else
119+
case mt of
120+
Root -> Empty
121+
MovieTrie c ismovie movie cmovieTrie -> if (isNothing cmovieTrie) then Empty
122+
else
123+
let
124+
a = fromMaybe Nil cmovieTrie
125+
in
126+
case a of
127+
Nil -> Empty
128+
Cons x xs -> search_Mhelper t (Cons x xs)
129+
130+
search_Mhelper :: Text -> (PList MovieTrie) -> Movie
131+
search_Mhelper t lmt =
132+
case lmt of
133+
Nil -> Empty
134+
Cons x xs -> if (fromMaybe ' ' (movieGetChar x)) *==* (head t)
135+
then searchMovieTitle (tail t) x
136+
else search_Mhelper t xs
137+
138+
-- searchMovieRating :: Int -> MovieTrie ->(PList Movie) -> (PList Movie)
139+
-- searchMovieTitle i mt lm =
140+
-- case mt of
141+
-- Root -> Nil
142+
-- MovieTrie c ismovie movie cmovieTrie ->
143+
-- let
144+
-- rating = getMovieRating (fromMaybe Empty movie)
145+
-- in if (rating > i) then Cons (fromMaybe Empty movie) (Search_MRhelper i cmovieTrie )
146+
-- else Search_MRhelper i cmovieTrie
147+
148+
-- search_MRhelper :: Int -> (PList MovieTrie) -> (PList Movie) -> (PList Movie)
149+
150+
-- getMovieRating :: Movie -> Int
151+
-- getMovieRating m = case m of
152+
-- Empty -> 0
153+
-- Movie movietitle releasedate director writers casinfo movitags rating -> rating
154+
155+
-- generateNode :: Char -> MovieTrie -> MovieTrie
156+
-- generateNode a mt =
157+
-- insertMovie :: Text -> MovieTrie -> MovieTrie
158+
-- insertMovie title mt =
159+
-- if isEmpty title then mt
160+
-- else if mt == End then
161+
-- let
162+
-- a = head title
163+
-- b = tail title
164+
-- curNode = MovieTrie Nothing (singleton a) insertMovie b End
165+
-- in curNode
166+
167+
isEmptyM :: Movie -> Bool
168+
isEmptyM m = case m of
169+
Empty -> True
170+
Movie _ _ _ _ _ _ _ ->False
171+
172+
genMovieList :: Int -> (PList Text)
173+
genMovieList i =
174+
if (i == 0)
175+
then Nil
176+
else
177+
let
178+
a = mod rand 10
179+
t = getRandomString a
180+
nt = genMovieList (i - 1)
181+
in Cons t nt
182+
183+
consMovieTrie :: (PList Text) -> MovieTrie ->MovieTrie
184+
consMovieTrie lt mt =
185+
case lt of
186+
Nil -> mt
187+
Cons x xs ->
188+
let
189+
movieContent = mkMovieContent x
190+
in consMovieTrie xs (insertMovie x Nothing movieContent mt)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#t
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Movies
2+
3+
type Text = Vector Char
4+
5+
getTitle :: Movie -> Text
6+
getTitle m = case m of
7+
Empty -> " "
8+
Movie mt rd d w ci movietags rating -> mt
9+
10+
gibbon_main =
11+
let
12+
movielist = genMovieList 100
13+
movie1 = fromMaybe " " (nth_plist movielist Nothing 10 )
14+
len1 = vlength movie1
15+
mt = consMovieTrie movielist Root
16+
mv = searchMovieTitle movie1 mt
17+
foundmovie = getTitle mv
18+
len2 = vlength foundmovie
19+
in len1 ==len2
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import Movies
2+
-- data Ttext = Ttext (Vector Char)
3+
printMovieTrie :: MovieTrie -> ()
4+
printMovieTrie mt = case mt of
5+
Root -> printsym (quote "nothing")
6+
MovieTrie ch ismovie movie lmt -> if (isNothing ch) then
7+
let
8+
_ = printsym (quote "/")
9+
in if (isNothing lmt) then ()
10+
else print_MThelper (fromMaybe Nil lmt)
11+
else let
12+
a = fromMaybe ' ' ch
13+
_ = printchar a
14+
in if (isNothing lmt) then ()
15+
else print_MThelper (fromMaybe Nil lmt)
16+
print_MThelper :: (PList MovieTrie)->()
17+
print_MThelper lmt = case lmt of
18+
Nil -> ()
19+
Cons x xs -> case x of
20+
Root -> print_MThelper xs
21+
MovieTrie ch ismovie movie lmt -> let
22+
_ = printchar (fromMaybe ' ' ch)
23+
_ = print_MThelper (fromMaybe Nil lmt)
24+
in print_MThelper xs
25+
26+
gibbon_main =
27+
-- let
28+
-- -- testMovie = Movie 'a' "MovieTitle" "ReleaseDate"
29+
-- -- testMovie = Empty
30+
-- ttext = Ttext "fsaf"
31+
-- -- testMovieTrie = MovieTrie (Just testMovie) (Just "Word") (Nothing)
32+
-- -- testMovieTrie = MovieTrie testMovie
33+
-- -- _ = printPacked testMovie
34+
35+
-- _ = printsym (quote "NEWLINE")
36+
-- _ = printPacked ttext
37+
-- -- _ = printsym (quote "NEWLINE")
38+
-- in ()
39+
-- putStrLn getRandomString 13
40+
let
41+
ri = mod rand 10
42+
ri2 = mod rand 10
43+
_ = printint ri2
44+
_ = printint ri
45+
-- smovie = mkMovieContent "titan"
46+
-- movieT = insertMovie "titan" Nothing smovie Root
47+
-- _ = printsym (quote " ")
48+
-- _ = printMovieTrie movieT
49+
-- movieT = insertMovie "titen" Nothing smovie movieT
50+
-- _ = printsym (quote " ")
51+
-- _ = printMovieTrie movieT
52+
-- _ = printsym (quote "test")
53+
-- mc = iterate (searchMovieTitle "tit" movieT)
54+
-- movieT = deleteMovie "titan" movieT
55+
-- _ = printsym (quote " ")
56+
-- _ = printMovieTrie movieT
57+
58+
-- _ = printPacked mc
59+
-- _ = printPacked movieT
60+
-- let
61+
-- _ = case movieT of
62+
-- Empty -> printsym (quote "empty")
63+
-- MovieTrie _ _ _ _ _ _ ->printsym (quote "valid")
64+
-- in (
65+
-- _ = printMovieTrie movieT
66+
-- _ = if isEmptyM mc then printsym(quote "notfound") else printsym (quote "found")
67+
-- _ = printPacked
68+
-- _ = printsym (quote "a")
69+
in ()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Movies
2+
3+
type Text = Vector Char
4+
5+
testDelete :: (PList Text) -> MovieTrie -> MovieTrie
6+
testDelete lt mt =
7+
case lt of
8+
Nil -> Root
9+
Cons x xs -> testDelete xs (deleteMovie x mt)
10+
11+
gibbon_main =
12+
let
13+
movielist = genMovieList 20
14+
mt = consMovieTrie movielist Root
15+
mt2 = iterate (testDelete movielist mt)
16+
in ()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Movies
2+
3+
testInsert :: Int -> MovieTrie -> MovieTrie
4+
testInsert i mt = if (i == 0) then mt
5+
else
6+
let
7+
title = getRandomString (mod rand 10)
8+
movieContent = mkMovieContent title
9+
in testInsert (i-1) (insertMovie title Nothing movieContent mt)
10+
gibbon_main =
11+
let
12+
mvt = iterate (testInsert 1000 Root)
13+
in ()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Movies
2+
3+
type Text = Vector Char
4+
5+
getTitle :: Movie -> Text
6+
getTitle m = case m of
7+
Empty -> " "
8+
Movie mt rd d w ci movietags rating -> mt
9+
10+
gibbon_main =
11+
let
12+
movielist = genMovieList 1000
13+
movie1 = fromMaybe " " (nth_plist movielist Nothing 100)
14+
mt = consMovieTrie movielist Root
15+
mv = iterate (searchMovieTitle movie1 mt)
16+
in ()

0 commit comments

Comments
 (0)