ZahirJS commited on
Commit
79ea405
·
verified ·
1 Parent(s): 693cb02

Update entity_relationship_generator.py

Browse files
Files changed (1) hide show
  1. entity_relationship_generator.py +192 -0
entity_relationship_generator.py CHANGED
@@ -4,6 +4,198 @@ from tempfile import NamedTemporaryFile
4
  import os
5
 
6
  def generate_entity_relationship_diagram(json_input: str, output_format: str) -> str:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  try:
8
  if not json_input.strip():
9
  return "Error: Empty input"
 
4
  import os
5
 
6
  def generate_entity_relationship_diagram(json_input: str, output_format: str) -> str:
7
+ """
8
+ Generates an entity relationship diagram from JSON input.
9
+
10
+ Args:
11
+ json_input (str): A JSON string describing the entity relationship diagram structure.
12
+ It must follow the Expected JSON Format Example below.
13
+
14
+ Expected JSON Format Example:
15
+ {
16
+ "entities": [
17
+ {
18
+ "name": "Customer",
19
+ "type": "strong",
20
+ "attributes": [
21
+ {"name": "customer_id", "type": "primary_key"},
22
+ {"name": "first_name", "type": "regular"},
23
+ {"name": "last_name", "type": "regular"},
24
+ {"name": "email", "type": "regular"},
25
+ {"name": "phone", "type": "multivalued", "multivalued": true},
26
+ {"name": "age", "type": "derived", "derived": true},
27
+ {"name": "address", "type": "composite", "composite": true}
28
+ ]
29
+ },
30
+ {
31
+ "name": "Order",
32
+ "type": "strong",
33
+ "attributes": [
34
+ {"name": "order_id", "type": "primary_key"},
35
+ {"name": "customer_id", "type": "foreign_key"},
36
+ {"name": "order_date", "type": "regular"},
37
+ {"name": "total_amount", "type": "regular"},
38
+ {"name": "status", "type": "regular"},
39
+ {"name": "shipping_address", "type": "composite", "composite": true}
40
+ ]
41
+ },
42
+ {
43
+ "name": "Product",
44
+ "type": "strong",
45
+ "attributes": [
46
+ {"name": "product_id", "type": "primary_key"},
47
+ {"name": "name", "type": "regular"},
48
+ {"name": "description", "type": "regular"},
49
+ {"name": "price", "type": "regular"},
50
+ {"name": "category_id", "type": "foreign_key"},
51
+ {"name": "stock_quantity", "type": "regular"}
52
+ ]
53
+ },
54
+ {
55
+ "name": "Category",
56
+ "type": "strong",
57
+ "attributes": [
58
+ {"name": "category_id", "type": "primary_key"},
59
+ {"name": "name", "type": "regular"},
60
+ {"name": "description", "type": "regular"},
61
+ {"name": "parent_category_id", "type": "foreign_key"}
62
+ ]
63
+ },
64
+ {
65
+ "name": "OrderItem",
66
+ "type": "weak",
67
+ "attributes": [
68
+ {"name": "order_id", "type": "primary_key"},
69
+ {"name": "product_id", "type": "primary_key"},
70
+ {"name": "quantity", "type": "regular"},
71
+ {"name": "unit_price", "type": "regular"},
72
+ {"name": "discount", "type": "regular"}
73
+ ]
74
+ },
75
+ {
76
+ "name": "Payment",
77
+ "type": "strong",
78
+ "attributes": [
79
+ {"name": "payment_id", "type": "primary_key"},
80
+ {"name": "order_id", "type": "foreign_key"},
81
+ {"name": "payment_method", "type": "regular"},
82
+ {"name": "amount", "type": "regular"},
83
+ {"name": "payment_date", "type": "regular"},
84
+ {"name": "transaction_id", "type": "regular"}
85
+ ]
86
+ },
87
+ {
88
+ "name": "Supplier",
89
+ "type": "strong",
90
+ "attributes": [
91
+ {"name": "supplier_id", "type": "primary_key"},
92
+ {"name": "company_name", "type": "regular"},
93
+ {"name": "contact_person", "type": "regular"},
94
+ {"name": "email", "type": "regular"},
95
+ {"name": "phone", "type": "multivalued", "multivalued": true},
96
+ {"name": "address", "type": "composite", "composite": true}
97
+ ]
98
+ },
99
+ {
100
+ "name": "Review",
101
+ "type": "weak",
102
+ "attributes": [
103
+ {"name": "customer_id", "type": "primary_key"},
104
+ {"name": "product_id", "type": "primary_key"},
105
+ {"name": "rating", "type": "regular"},
106
+ {"name": "comment", "type": "regular"},
107
+ {"name": "review_date", "type": "regular"}
108
+ ]
109
+ }
110
+ ],
111
+ "relationships": [
112
+ {
113
+ "name": "Places",
114
+ "type": "regular",
115
+ "entities": ["Customer", "Order"],
116
+ "cardinalities": {
117
+ "Customer": "1",
118
+ "Order": "N"
119
+ }
120
+ },
121
+ {
122
+ "name": "Contains",
123
+ "type": "identifying",
124
+ "entities": ["Order", "OrderItem"],
125
+ "cardinalities": {
126
+ "Order": "1",
127
+ "OrderItem": "N"
128
+ }
129
+ },
130
+ {
131
+ "name": "Includes",
132
+ "type": "regular",
133
+ "entities": ["OrderItem", "Product"],
134
+ "cardinalities": {
135
+ "OrderItem": "N",
136
+ "Product": "1"
137
+ }
138
+ },
139
+ {
140
+ "name": "BelongsTo",
141
+ "type": "regular",
142
+ "entities": ["Product", "Category"],
143
+ "cardinalities": {
144
+ "Product": "N",
145
+ "Category": "1"
146
+ }
147
+ },
148
+ {
149
+ "name": "ProcessedBy",
150
+ "type": "regular",
151
+ "entities": ["Order", "Payment"],
152
+ "cardinalities": {
153
+ "Order": "1",
154
+ "Payment": "1"
155
+ }
156
+ },
157
+ {
158
+ "name": "Supplies",
159
+ "type": "regular",
160
+ "entities": ["Supplier", "Product"],
161
+ "cardinalities": {
162
+ "Supplier": "N",
163
+ "Product": "M"
164
+ }
165
+ },
166
+ {
167
+ "name": "Writes",
168
+ "type": "weak",
169
+ "entities": ["Customer", "Review"],
170
+ "cardinalities": {
171
+ "Customer": "1",
172
+ "Review": "N"
173
+ }
174
+ },
175
+ {
176
+ "name": "ReviewsProduct",
177
+ "type": "weak",
178
+ "entities": ["Review", "Product"],
179
+ "cardinalities": {
180
+ "Review": "N",
181
+ "Product": "1"
182
+ }
183
+ },
184
+ {
185
+ "name": "Subcategory",
186
+ "type": "regular",
187
+ "entities": ["Category", "Category"],
188
+ "cardinalities": {
189
+ "Category": "1",
190
+ "Category": "N"
191
+ }
192
+ }
193
+ ]
194
+ }
195
+
196
+ Returns:
197
+ str: The filepath to the generated PNG image file.
198
+ """
199
  try:
200
  if not json_input.strip():
201
  return "Error: Empty input"