-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathted_talk_dag.py
More file actions
635 lines (519 loc) · 16.3 KB
/
Copy pathted_talk_dag.py
File metadata and controls
635 lines (519 loc) · 16.3 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
#!/usr/bin/env python3
"""
Airflow DAG generated from Alteryx workflow: Ted talk Workflow
Source: Ted talk Workflow.yxmd
Generated: 2026-02-23 18:37:17
"""
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python import PythonOperator
import pandas as pd
import os
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
}
dag = DAG(
'ted_talk_workflow',
default_args=default_args,
description='DAG generated from Alteryx workflow: Ted talk Workflow',
schedule_interval='@daily',
start_date=datetime(2024, 1, 1),
catchup=False,
tags=['alteryx', 'generated'],
)
# Read CSV file
def read_2(context):
import pandas as pd
ti = context['ti']
df = pd.read_csv('C:\Users\ash_s\Downloads\ted_main.csv')
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_read_2 = PythonOperator(
task_id='read_2',
python_callable=read_2,
dag=dag,
)
# Browse/Print data
def browse_3(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_2')
df = pd.read_json(json_data)
print(f"Browse 3 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_3 = PythonOperator(
task_id='browse_3',
python_callable=browse_3,
dag=dag,
)
# Apply formulas
def apply_formulas_4(context):
import pandas as pd
import re
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_2')
df = pd.read_json(json_data)
# Apply formulas
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_apply_formulas_4 = PythonOperator(
task_id='apply_formulas_4',
python_callable=apply_formulas_4,
dag=dag,
)
# Browse/Print data
def browse_5(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_4')
df = pd.read_json(json_data)
print(f"Browse 5 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_5 = PythonOperator(
task_id='browse_5',
python_callable=browse_5,
dag=dag,
)
# Apply formulas
def apply_formulas_6(context):
import pandas as pd
import re
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_4')
df = pd.read_json(json_data)
# Apply formulas
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_apply_formulas_6 = PythonOperator(
task_id='apply_formulas_6',
python_callable=apply_formulas_6,
dag=dag,
)
# Browse/Print data
def browse_7(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_6')
df = pd.read_json(json_data)
print(f"Browse 7 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_7 = PythonOperator(
task_id='browse_7',
python_callable=browse_7,
dag=dag,
)
# Sort data
def sort_data_8(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_6')
df = pd.read_json(json_data)
# Sort by:
if '':
df = df.sort_values(by=[])
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_sort_data_8 = PythonOperator(
task_id='sort_data_8',
python_callable=sort_data_8,
dag=dag,
)
# Sample data
def sample_data_10(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_8')
df = pd.read_json(json_data)
# Sample: First 5 rows
if 'First' == 'First':
df = df.head(5)
elif 'First' == 'Random':
df = df.sample(n=min(5, len(df)), random_state=42)
elif 'First' == 'Last':
df = df.tail(5)
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_sample_data_10 = PythonOperator(
task_id='sample_data_10',
python_callable=sample_data_10,
dag=dag,
)
# Sort data
def sort_data_11(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_10')
df = pd.read_json(json_data)
# Sort by:
if '':
df = df.sort_values(by=[])
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_sort_data_11 = PythonOperator(
task_id='sort_data_11',
python_callable=sort_data_11,
dag=dag,
)
# Table composer
def compose_table_12(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_11')
df = pd.read_json(json_data)
# Compose table with selected fields
# This would format the data for display
print(f"Table composed: {df.shape}")
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_compose_table_12 = PythonOperator(
task_id='compose_table_12',
python_callable=compose_table_12,
dag=dag,
)
# Browse/Print data
def browse_13(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_10')
df = pd.read_json(json_data)
print(f"Browse 13 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_13 = PythonOperator(
task_id='browse_13',
python_callable=browse_13,
dag=dag,
)
# Browse/Print data
def browse_14(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_12')
df = pd.read_json(json_data)
print(f"Browse 14 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_14 = PythonOperator(
task_id='browse_14',
python_callable=browse_14,
dag=dag,
)
# Aggregate data
def aggregate_data_15(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_6')
df = pd.read_json(json_data)
# Group by: []
# Aggregations: []
pass
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_aggregate_data_15 = PythonOperator(
task_id='aggregate_data_15',
python_callable=aggregate_data_15,
dag=dag,
)
# Sort data
def sort_data_16(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_15')
df = pd.read_json(json_data)
# Sort by:
if '':
df = df.sort_values(by=[])
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_sort_data_16 = PythonOperator(
task_id='sort_data_16',
python_callable=sort_data_16,
dag=dag,
)
# Apply formulas
def apply_formulas_17(context):
import pandas as pd
import re
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_16')
df = pd.read_json(json_data)
# Apply formulas
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_apply_formulas_17 = PythonOperator(
task_id='apply_formulas_17',
python_callable=apply_formulas_17,
dag=dag,
)
# Sample data
def sample_data_20(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_18')
df = pd.read_json(json_data)
# Sample: First 5 rows
if 'First' == 'First':
df = df.head(5)
elif 'First' == 'Random':
df = df.sample(n=min(5, len(df)), random_state=42)
elif 'First' == 'Last':
df = df.tail(5)
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_sample_data_20 = PythonOperator(
task_id='sample_data_20',
python_callable=sample_data_20,
dag=dag,
)
# Browse/Print data
def browse_21(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_18')
df = pd.read_json(json_data)
print(f"Browse 21 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_21 = PythonOperator(
task_id='browse_21',
python_callable=browse_21,
dag=dag,
)
# Table composer
def compose_table_22(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_20')
df = pd.read_json(json_data)
# Compose table with selected fields
# This would format the data for display
print(f"Table composed: {df.shape}")
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_compose_table_22 = PythonOperator(
task_id='compose_table_22',
python_callable=compose_table_22,
dag=dag,
)
# Browse/Print data
def browse_23(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_22')
df = pd.read_json(json_data)
print(f"Browse 23 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_23 = PythonOperator(
task_id='browse_23',
python_callable=browse_23,
dag=dag,
)
# Aggregate data
def aggregate_data_24(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_6')
df = pd.read_json(json_data)
# Group by: []
# Aggregations: []
pass
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_aggregate_data_24 = PythonOperator(
task_id='aggregate_data_24',
python_callable=aggregate_data_24,
dag=dag,
)
# Sort data
def sort_data_25(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_24')
df = pd.read_json(json_data)
# Sort by:
if '':
df = df.sort_values(by=[])
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_sort_data_25 = PythonOperator(
task_id='sort_data_25',
python_callable=sort_data_25,
dag=dag,
)
# Create chart
def create_chart_26(context):
import pandas as pd
import matplotlib.pyplot as plt
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_25')
df = pd.read_json(json_data)
# Create chart based on configuration
# This would implement the specific chart type
print(f"Chart created: {df.shape}")
return df.shape[0]
task_create_chart_26 = PythonOperator(
task_id='create_chart_26',
python_callable=create_chart_26,
dag=dag,
)
# Browse/Print data
def browse_27(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_26')
df = pd.read_json(json_data)
print(f"Browse 27 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_27 = PythonOperator(
task_id='browse_27',
python_callable=browse_27,
dag=dag,
)
# Apply formulas
def apply_formulas_28(context):
import pandas as pd
import re
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_6')
df = pd.read_json(json_data)
# Apply formulas
# field:
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_apply_formulas_28 = PythonOperator(
task_id='apply_formulas_28',
python_callable=apply_formulas_28,
dag=dag,
)
# Browse/Print data
def browse_29(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_28')
df = pd.read_json(json_data)
print(f"Browse 29 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_29 = PythonOperator(
task_id='browse_29',
python_callable=browse_29,
dag=dag,
)
# Table composer
def compose_table_30(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_28')
df = pd.read_json(json_data)
# Compose table with selected fields
# This would format the data for display
print(f"Table composed: {df.shape}")
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_compose_table_30 = PythonOperator(
task_id='compose_table_30',
python_callable=compose_table_30,
dag=dag,
)
# Browse/Print data
def browse_31(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_30')
df = pd.read_json(json_data)
print(f"Browse 31 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_31 = PythonOperator(
task_id='browse_31',
python_callable=browse_31,
dag=dag,
)
# Browse/Print data
def browse_33(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_32')
df = pd.read_json(json_data)
print(f"Browse 33 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_33 = PythonOperator(
task_id='browse_33',
python_callable=browse_33,
dag=dag,
)
# Table composer
def compose_table_34(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_32')
df = pd.read_json(json_data)
# Compose table with selected fields
# This would format the data for display
print(f"Table composed: {df.shape}")
ti.xcom_push(key='data', value=df.to_json())
return df.shape[0]
task_compose_table_34 = PythonOperator(
task_id='compose_table_34',
python_callable=compose_table_34,
dag=dag,
)
# Browse/Print data
def browse_35(context):
import pandas as pd
ti = context['ti']
json_data = ti.xcom_pull(key='data', task_ids='read_34')
df = pd.read_json(json_data)
print(f"Browse 35 - Shape: {df.shape}")
print(df.head())
return df.shape[0]
task_browse_35 = PythonOperator(
task_id='browse_35',
python_callable=browse_35,
dag=dag,
)
# Define task dependencies
task_2 >> task_3
task_2 >> task_4
task_4 >> task_5
task_4 >> task_6
task_6 >> task_7
task_6 >> task_8
task_6 >> task_15
task_6 >> task_24
task_6 >> task_28
task_6 >> task_32
task_8 >> task_10
task_10 >> task_11
task_10 >> task_13
task_11 >> task_12
task_12 >> task_14
task_15 >> task_16
task_16 >> task_17
task_17 >> task_18
task_18 >> task_20
task_18 >> task_21
task_20 >> task_22
task_22 >> task_23
task_24 >> task_25
task_25 >> task_26
task_26 >> task_27
task_28 >> task_29
task_28 >> task_30
task_30 >> task_31
task_32 >> task_33
task_32 >> task_34
task_34 >> task_35
if __name__ == "__main__":
dag.test()