-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecom_structs.c
1960 lines (1540 loc) · 54.8 KB
/
recom_structs.c
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// recom_structs.c
//
// Christina-Theano Kylafi
// AM: 1115201200077
#include "recom.h"
struct coin_ref_list
{
char* coin_ref;
struct coin_ref_list* next;
};
struct crypto_coins
{
int tot_num;
struct coin_ref_list* ref_list;
struct coin_ref_list* last_node;
char** coin_refs[1];
};
struct sentim_score_map
{
char* str;
double score;
};
struct tweet_content
{
char* word;
struct tweet_content* next;
};
struct coins_in_tweet
{
int coin_index;
char* name;
struct coins_in_tweet* next;
};
struct tweets
{
long long tot_words;
long long user_id;
long long tweet_id;
double tweet_score;
struct tweet_content* content;
struct tweet_content* last_word;
int tot_coins;
struct coins_in_tweet* coins;
struct coins_in_tweet* coins_last_node;
};
struct list_of_tweets
{
long long tweet;
struct list_of_tweets* next;
};
struct users
{
long long user_id;
int empty_user; //if the vector is 0, it is of no use!
double* user_crypto[1]; //vector of user-crypto currency sentiment
double* user_crypto_saved[1];
long long tot_tweets;
struct list_of_tweets* first_tweet;
struct list_of_tweets* last_tweet;
int tot_coins;
struct coins_in_tweet* coins;
struct coins_in_tweet* coins_last_node;
double average_rating;
//5 best - real users
struct coins_in_tweet* best_5_real[5];
int cluster_num_real; //cluster number - real users 2.A
//2 best - virtual users
struct coins_in_tweet* best_2_represent[2];
int cluster_num_virtual; //cluster number - virtual 2.B
};
//struct functions
//coin_ref_list
//get
char* get_coinref_coin_ref_list(struct coin_ref_list* list)
{ return ( list -> coin_ref ); }
struct coin_ref_list* get_next_coin_ref_list(struct coin_ref_list* list)
{ return ( list -> next ); }
char* get_nth_coinref_coin_ref_list(struct coin_ref_list* list, long long n)
{
struct coin_ref_list* templist = NULL;
long long counter = 0;
templist = list;
while( (templist != NULL) && (counter < n) )
{
counter++;
templist = get_next_coin_ref_list(templist);
}
char* element = NULL;
if(templist!=NULL)
{
element = get_coinref_coin_ref_list(templist);
}
return element;
}
//save
void save_coinref_coin_ref_list(struct crypto_coins* coins[], long long pos, char* string)
{
struct coin_ref_list* newnode = NULL;
newnode = malloc(sizeof(struct coin_ref_list));
newnode -> coin_ref = string;
newnode -> next = NULL;
( coins[0][pos].last_node ) -> next = newnode;
coins[0][pos].last_node = newnode;
coins[0][pos].tot_num ++;
}
//crypto_coins
//get
int get_tot_num_crypto_coins(struct crypto_coins* coins[], long long pos)
{ return ( coins[0][pos].tot_num ); }
struct coin_ref_list* get_coinreflist_crypto_coins(struct crypto_coins* coins[], long long pos)
{ return( coins[0][pos].ref_list ); }
char* get_coinref_crypto_coins(struct crypto_coins* coins[], long long pos)
{ return ( ( coins[0][pos].ref_list ) -> coin_ref ); }
struct coin_ref_list* get_lastnode_crypto_coins(struct crypto_coins* coins[], long long pos)
{ return( coins[0][pos].ref_list ); }
//save
void save_crypto_coin(struct crypto_coins* coins[], long long pos, char* string)
{
struct coin_ref_list* newnode = NULL;
newnode = malloc(sizeof(struct coin_ref_list));
newnode -> coin_ref = string;
newnode -> next = NULL;
coins[0][pos].ref_list = newnode;
coins[0][pos].last_node = coins[0][pos].ref_list;
coins[0][pos].tot_num = 1;
}
void crypto_coins_create_array(struct crypto_coins* coins[], long long coins_num)
{
int tempnum = 0;
for (long long u = 0; u < coins_num; u++)
{
tempnum = get_tot_num_crypto_coins(coins, u);
//printf("\nCoin refs: %d", tempnum);
coins[0][u].coin_refs[0] = malloc (tempnum * sizeof(char*));
struct coin_ref_list* templist = get_coinreflist_crypto_coins(coins, u);
for (int h = 0; h < tempnum; h++)
{
coins[0][u].coin_refs[0][h] = get_coinref_coin_ref_list(templist);
templist = get_next_coin_ref_list(templist);
}
}
}
//more
int is_a_coin(char* string_to_check, struct crypto_coins* coins[], int coins_num)
{
int index = -1, is_same = 0, temprefs = 0;
struct coin_ref_list* templist = NULL;
//printf("|%s|", string_to_check);
for (int g = 0; g < coins_num; g++)
{
templist = get_coinreflist_crypto_coins(coins, g);
temprefs = coins[0][g].tot_num;
for(int k = 0; k < temprefs; k++)
{
is_same = check_if_same_str(coins[0][g].coin_refs[0][k], string_to_check);
if(is_same)
{
//printf("Is_a_coin!! index: %d, name: %s", g, coins[0][g].coin_refs[0][k]);
index = g;
return index;
}
// templist = get_next_coin_ref_list(templist);
}
}
return index;
}
char* name_of_coin_from_pos(struct crypto_coins* coins[], int coins_num, int index)
{
char* name = NULL;
int tot_num_of_refs = -9;
if(index>=0)
{
tot_num_of_refs = coins[0][index].tot_num;
if(tot_num_of_refs < 5 )
{
name = coins[0][index].coin_refs[0][0];
}
else
{
name = coins[0][index].coin_refs[0][4];
}
}
return name;
}
//sentim_score_map
//get
char* get_srt_sentim_score_map(struct sentim_score_map* sentimap[], long long pos)
{ return ( sentimap[0][pos].str ); }
double get_score_sentim_score_map(struct sentim_score_map* sentimap[], long long pos)
{ return ( sentimap[0][pos].score ); }
double get_word_score(struct sentim_score_map* sentim_map[], long long sentim_map_size, char* tempstr)
{
double score = 0.0;
int same = 0;
for(long long h = 0; h < sentim_map_size; h++)
{
same = check_if_same_str(tempstr, get_srt_sentim_score_map(sentim_map, h) );
//printf("\n|%s| == |%s| ", tempstr,get_srt_sentim_score_map(sentim_map, h) );
if(same)
{
score = get_score_sentim_score_map(sentim_map, h);
//printf("\n-> %lf\n", score);
//sleep(10);
}
}
return score;
}
//save
void save_srt_sentim_score_map(struct sentim_score_map* sentimap[], long long pos, char* string)
{ sentimap[0][pos].str = string ;}
void save_score_sentim_score_map(struct sentim_score_map* sentimap[], long long pos, double score)
{ sentimap[0][pos].score = score ;}
//tweet_content
//get
char* get_word_tweet_content(struct tweet_content* list)
{ return ( list -> word ); }
struct tweet_content* get_next_tweet_content(struct tweet_content* list)
{ return ( list -> next ); }
//save
void save_word_tweet_content(struct tweets* tweets[], long long pos, char* word)
{
struct tweet_content* newnode = NULL;
newnode = malloc(sizeof(struct tweet_content));
newnode -> next = NULL;
newnode -> word = word;
(tweets[0][pos].last_word) -> next = newnode;
tweets[0][pos].last_word = newnode;
tweets[0][pos].tot_words++;
}
//coins_in_tweet
//init
//tweets
//init
void tweets_init(struct tweets* tweets[], long long tweets_num)
{
for(long long k = 0; k < tweets_num; k++)
{
tweets[0][k].tot_words = -9;
tweets[0][k].user_id = -9;
tweets[0][k].tweet_id = -9;
tweets[0][k].tweet_score = -9;
tweets[0][k].content = NULL;
tweets[0][k].last_word = NULL;
tweets[0][k].tot_coins = -9;
tweets[0][k].coins = NULL;
tweets[0][k].coins_last_node = NULL;
}
}
//get
long long get_tot_words_tweets(struct tweets* tweets[], long long pos)
{ return (tweets[0][pos].tot_words); }
long long get_user_id_tweets(struct tweets* tweets[], long long pos)
{ return (tweets[0][pos].user_id); }
long long get_tweet_id_tweets(struct tweets* tweets[], long long pos)
{ return (tweets[0][pos].tweet_id); }
double get_tweet_score_tweets(struct tweets* tweets[], long long pos)
{ return (tweets[0][pos].tweet_score); }
struct tweet_content* get_tweet_content_tweets(struct tweets* tweets[], long long pos)
{ return (tweets[0][pos].content); }
struct tweet_content* get_last_word_tweets(struct tweets* tweets[], long long pos)
{ return (tweets[0][pos].last_word); }
long long get_pos_from_id_tweets(struct tweets* tweets[], long long tweets_num, long long tweet_id)
{
long long pos = -1;
for (long long o = 0; o < tweets_num; o++)
{
if( (tweets[0][o].tweet_id) == tweet_id)
{
pos = o;
return pos;
}
}
return pos;
}
//save
void save_word_tweets(struct tweets* tweets[], long long pos, char* word)
{
struct tweet_content* newnode = NULL;
newnode = malloc(sizeof(struct tweet_content));
newnode -> next = NULL;
newnode -> word = word;
tweets[0][pos].content = newnode;
tweets[0][pos].last_word = tweets[0][pos].content;
tweets[0][pos].tot_words = 1;
}
void save_user_id_tweets(struct tweets* tweets[], long long pos, long long id)
{ tweets[0][pos].user_id = id; }
void save_tweet_id_tweets(struct tweets* tweets[], long long pos, long long id)
{ tweets[0][pos].tweet_id = id; }
void save_tweet_score_tweets(struct tweets* tweets[], long long pos, double score)
{ tweets[0][pos].tweet_score = score; }
//more
void init_coins_in_tweet(int coin, struct tweets* tweets[], long long pos, struct crypto_coins* coins[])
{
struct coins_in_tweet* newnode = NULL;
newnode = malloc(sizeof(struct coins_in_tweet));
newnode -> coin_index = coin;
// char* tempname = NULL;
// tempname = get_nth_coinref_coin_ref_list(get_coinreflist_crypto_coins(coins,pos),5);
// if(tempname==NULL)
// {
// tempname = get_nth_coinref_coin_ref_list(coins[0][pos].ref_list,1);
// }
newnode -> name = NULL;
newnode -> next = NULL;
tweets[0][pos].coins = newnode;
tweets[0][pos].coins_last_node = tweets[0][pos].coins;
tweets[0][pos].tot_coins = 1;
}
void add_coins_in_tweet(int coin, struct tweets* tweets[], long long pos, struct crypto_coins* coins[])
{
struct coins_in_tweet* newnode = NULL, *templist = NULL;
int exists = 0;
templist = tweets[0][pos].coins;
while (templist!=NULL)
{
if( (templist -> coin_index) == coin )
{
exists = 1;
break;
}
templist = templist -> next;
}
if(!exists)
{
newnode = malloc(sizeof(struct coins_in_tweet));
newnode -> coin_index = coin;
// char* tempname = NULL;
// tempname = get_nth_coinref_coin_ref_list(coins[0][pos].ref_list,5);
// if(tempname==NULL)
// {
// tempname = get_nth_coinref_coin_ref_list(coins[0][pos].ref_list,1);
// }
// newnode -> coin_name = tempname;
newnode -> next = NULL;
(tweets[0][pos].coins_last_node) -> next = newnode;
tweets[0][pos].coins_last_node = newnode;
tweets[0][pos].tot_coins ++;
}
}
//get_size of structs
size_t get_size_coin_ref_list()
{ return sizeof(struct coin_ref_list); }
size_t get_size_crypto_coins()
{ return sizeof(struct crypto_coins); }
size_t get_size_sentim_score_map()
{ return sizeof(struct sentim_score_map); }
size_t get_size_tweet_content()
{ return sizeof(struct tweet_content); }
size_t get_size_tweets()
{ return sizeof(struct tweets); }
size_t get_size_list_of_tweets()
{ return sizeof(struct list_of_tweets); }
size_t get_size_users()
{ return sizeof(struct users); }
//users
void users_init(struct users* users[], long long users_num, int coins_size)
{
for (long long k = 0; k < users_num; k++)
{
users[0][k].user_id = -9;
users[0][k].empty_user = -9;
users[0][k].user_crypto[0] = NULL;
users[0][k].user_crypto[0] = malloc(sizeof(double)*coins_size); //the vector of users-cryptocurrency
users[0][k].user_crypto_saved[0] = NULL;
users[0][k].user_crypto_saved[0] = malloc(sizeof(double)*coins_size); //the vector of users-cryptocurrency
users[0][k].first_tweet = NULL;
users[0][k].last_tweet = NULL;
users[0][k].tot_coins = -9;
users[0][k].coins = NULL;
users[0][k].coins_last_node = NULL;
users[0][k].average_rating = INFINITY;
for(int i = 0; i < 5; i++)
{
users[0][k].best_5_real[i] = malloc(sizeof(struct coins_in_tweet));
(users[0][k].best_5_real[i])->coin_index = -9;
(users[0][k].best_5_real[i])->name = NULL;
if(i < 2)
{
users[0][k].best_2_represent[i] = malloc(sizeof(struct coins_in_tweet));
(users[0][k].best_2_represent[i])->coin_index = -9;
(users[0][k].best_2_represent[i])->name = NULL;
}
}
}
}
//get
long long get_user_id_users(struct users* users[], long long pos)
{ return (users[0][pos].user_id); }
int get_empty_user_users(struct users* users[], long long pos)
{ return users[0][pos].empty_user; }
double get_user_crypto_rating_users(struct users* users[], long long pos, int coin_pos)
{
double rating = 0;
rating = users[0][pos].user_crypto[0][coin_pos];
return rating;
}
long long get_tot_tweets_users(struct users* users[], long long users_num)
{ return (users[0][users_num].tot_tweets); }
int get_tot_coins_users(struct users* users[], long long users_num)
{ return (users[0][users_num].tot_coins); }
double get_average_rating_users(struct users* users[], long long pos)
{ return (users[0][pos].average_rating); }
long long get_pos_from_id_users(struct users* users[], long long users_num, long long user_id)
{
long long pos = -1;
for (long long o = 0; o < users_num; o++)
{
if( (users[0][o].user_id) == user_id)
{
pos = o;
return pos;
}
}
return pos;
}
struct coins_in_tweet* get_nth_best_5_real_users(struct users* users[], long long pos, int n)
{ return (users[0][pos].best_5_real[n] ); }
int get_cluster_num_real_users(struct users* users[], long long pos)
{ return (users[0][pos].cluster_num_real); }
struct coins_in_tweet* get_nth_best_2_represent_users(struct users* users[], long long pos, int n)
{ return (users[0][pos].best_2_represent[n] ); }
int get_cluster_num_virtual_users(struct users* users[], long long pos)
{ return (users[0][pos].cluster_num_virtual); }
//save
void save_empty_user_users(struct users* users[], long long pos, int is_empty)
{ users[0][pos].empty_user = is_empty; }
void save_average_rating_users(struct users* users[], long long pos, double rating)
{ users[0][pos].average_rating = rating; }
void save_user_crypto_rating_users(struct users* users[], long long pos, int coin_pos, double new_rating)
{ //printf("\n%d\n" , __LINE__);
users[0][pos].user_crypto[0][coin_pos] = new_rating;
//printf("\n%d\n" , __LINE__);
}
void save_nth_best_5_real_users(struct users* users[], long long pos, int n, int coin_index, char* name)
{
users[0][pos].best_5_real[n]->coin_index = coin_index;
users[0][pos].best_5_real[n]->name = name;
}
void save_cluster_num_real_users(struct users* users[], long long pos, int cluster_num_real)
{ users[0][pos].cluster_num_real = cluster_num_real; }
void save_nth_best_2_represent_users(struct users* users[], long long pos, int n, int coin_index, char* name)
{
users[0][pos].best_2_represent[n]->coin_index = coin_index;
users[0][pos].best_2_represent[n]->name = name;
}
void save_cluster_num_virtual_users(struct users* users[], long long pos, int cluster_num_virtual)
{ users[0][pos].cluster_num_virtual = cluster_num_virtual; }
void save_tot_coins_users(struct users* users[], long long pos, int coins_in_user)
{ users[0][pos].tot_coins = coins_in_user ; }
//copy
void copy_users(struct users* users[], long long pos1, struct users* users_with_coins[], long long pos2, int coins_num)
{
//check - - - -
// //5 best - real users
// struct coins_in_tweet* best_5_real[5];
// int cluster_num_real; //cluster number - real users 2.A
// //2 best - virtual users
// struct coins_in_tweet* best_2_represent[2];
// int cluster_num_virtual; //cluster number - virtual 2.B
users_with_coins[0][pos2].user_id = users[0][pos1].user_id;
users_with_coins[0][pos2].empty_user = users[0][pos1].empty_user;
//users_with_coins[0][pos2].user_crypto[0] = users[0][pos1].user_crypto[0];
for(int i = 0; i < coins_num; i++)
{
users_with_coins[0][pos2].user_crypto[0][i] = users[0][pos1].user_crypto[0][i];
}
//users_with_coins[0][pos2].user_crypto_saved[0] = users[0][pos1].user_crypto_saved[0];
// for(int i = 0; i < coins_num; i++)
// {
// users_with_coins[0][pos2].user_crypto_saved[0][i] = users[0][pos1].user_crypto_saved[0][i];
// }
users_with_coins[0][pos2].tot_tweets = users[0][pos1].tot_tweets;
users_with_coins[0][pos2].first_tweet = users[0][pos1].first_tweet;
users_with_coins[0][pos2].last_tweet = users[0][pos1].last_tweet;
users_with_coins[0][pos2].tot_coins = users[0][pos1].tot_coins;
users_with_coins[0][pos2].coins = users[0][pos1].coins;
users_with_coins[0][pos2].coins_last_node = users[0][pos1].coins_last_node;
users_with_coins[0][pos2].average_rating = users[0][pos1].average_rating;
}
void user_crypto_save_users(struct users* users[], long long users_num, int dimension_of_coords)
{
for (long long i = 0; i < users_num; i++)
{
for( int y = 0; y < dimension_of_coords; y++)
{
users[0][i].user_crypto_saved[0][y] = users[0][i].user_crypto[0][y] ;
}
}
}
void retrieve_saved_user_crypto_ratings_users(struct users* users[], long long users_num, int coins_size)
{
for (long long y = 0; y < users_num; y++)
{
for (int i = 0; i < coins_size; i++)
{
//printf("\n %lf \n", users[0][y].user_crypto_saved[0][i]);
users[0][y].user_crypto[0][i] = users[0][y].user_crypto_saved[0][i] ;
}
}
}
// void restart_users(struct users* users[], long long users_num, int coins_size)
// {
// retrieve_saved_user_crypto_ratings_users(users, users_num, coins_size);
// }
void clear_users(struct users* users[], long long users_num)
{
for ( long long i = 0; i < users_num; i++)
{
for(int y = 0; y < 5; y++)
{
if(y < 2)
{
users[0][i].best_2_represent[y]->coin_index = -9;
(users[0][i].best_2_represent[y])->name = NULL;
}
users[0][i].best_5_real[y]->coin_index = -9;
(users[0][i].best_5_real[y])->name = NULL;
}
}
}
//create
int add_tweet_to_user(struct users* users[], long long pos, long long tweet_index)
{
if( (users[0][pos].first_tweet) == NULL ) //init
{
struct list_of_tweets* newnode = NULL;
newnode = malloc(sizeof(struct list_of_tweets));
newnode -> tweet = tweet_index;
newnode -> next = NULL;
users[0][pos].first_tweet = newnode;
users[0][pos].last_tweet = users[0][pos].first_tweet;
users[0][pos].tot_tweets = 1;
}
else //else add at the end
{
struct list_of_tweets* newnode = NULL;
newnode = malloc(sizeof(struct list_of_tweets));
newnode -> tweet = tweet_index;
newnode -> next = NULL;
(users[0][pos].last_tweet) -> next = newnode;
users[0][pos].last_tweet = newnode;
(users[0][pos].tot_tweets) ++;
}
return 6;
}
int user_coin_score(struct users* users[], long long users_counter, struct tweets* tweets[], long long u, struct coins_in_tweet* templist)
{
int known_rating = 0;
double temp = users[0][users_counter].user_crypto[0][templist -> coin_index];
//printf("\nUser: %lld - Tweet: %lld - score: %lf + %lf = ", users_counter, u, temp, tweets[0][u].tweet_score);
if(temp == INFINITY)
{
known_rating = 1;
users[0][users_counter].user_crypto[0][templist -> coin_index] = tweets[0][u].tweet_score;
}
else
{
(users[0][users_counter].user_crypto[0][templist -> coin_index]) += tweets[0][u].tweet_score;
}
//printf("%lf", users[0][users_counter].user_crypto[0][templist -> coin_index]);
return known_rating;
}
long long create_users(struct users* users[], long long users_num, struct tweets* tweets[], long long tweets_num, struct crypto_coins* coins[], int coins_size )
{
long long known_ratings = 0;
long long temp_user_id = -9;
long long users_counter = 0;
//long long u = 0;
for (long long h = 0; h < users_num; h++)
{
users[0][h].tot_coins = 0;
users[0][h].tot_tweets = 0;
}
for(long long u = 0; u < tweets_num; u++)
{
if(temp_user_id < 0)
{
temp_user_id = tweets[0][u].user_id ;
users[0][users_counter].user_id = temp_user_id;
//users[0][users_counter].user_crypto[0] = malloc(sizeof(double)*coins_size); //the vector of users-cryptocurrency
for(long long k = 0; k < coins_size; k++)
{
users[0][users_counter].user_crypto[0][k] = INFINITY;
}
// for(long long k = 0; k < coins_size; k++)
// {
// printf("\n%lf", users[0][users_counter].user_crypto[0][k] );
// }
}
else
{
if(temp_user_id!=tweets[0][u].user_id)
{
users_counter++;
temp_user_id = tweets[0][u].user_id;
users[0][users_counter].user_id = temp_user_id;
//users[0][users_counter].user_crypto[0] = malloc(sizeof(double)*coins_size); //the vector of users-cryptocurrency
for(long long k = 0; k < coins_size; k++)
{
users[0][users_counter].user_crypto[0][k] = INFINITY;
}
}
}
add_tweet_to_user(users, users_counter, u);
struct coins_in_tweet* templist = NULL;
templist = tweets[0][u].coins;
while(templist!=NULL)
{
//printf("\nuser%lld - score: %lf", users[0][users_counter].user_id, tweets[0][u].tweet_score);
if(users[0][users_counter].tot_coins == 0)
{
init_coins_in_user(templist->coin_index, users, users_counter, coins);
}
else
{
add_coins_in_user(templist->coin_index, users, users_counter, coins);
}
known_ratings += user_coin_score(users, users_counter, tweets, u, templist);
//printf("%d", __LINE__);
templist = templist->next;
}
//u++;
}
return known_ratings;
}
long long create_represent(struct cluster* clusters[], int clusters_num, struct users* users_representatives[], struct tweets* tweets[], long long tweets_num, struct crypto_coins* coins[], int coins_size )
{
//long long temp_user_id = -9;
//long long users_counter = clusters_num;
//long long u = 0;
long long tweet_index = -9, tweet_id = -9;
for (long long h = 0; h < clusters_num; h++)
{
users_representatives[0][h].tot_coins = 0;
users_representatives[0][h].tot_tweets = 0;
}
for(long long u = 0; u < clusters_num; u++)
{
users_representatives[0][u].user_id = u;
// users_representatives[0][u].user_crypto[0] = malloc(sizeof(double)*coins_size); //the vector of users-cryptocurrency
for(long long k = 0; k < coins_size; k++)
{
users_representatives[0][u].user_crypto[0][k] = INFINITY;
}
// for(long long k = 0; k < coins_size; k++)
// {
// printf("\n%lf", users[0][users_counter].user_crypto[0][k] );
// }
struct points_in_cluster* templist_points_in_cluster = NULL;
templist_points_in_cluster = get_firstpoint_in_cluster(u, clusters);
struct coins_in_tweet* templist = NULL;
while(templist_points_in_cluster!=NULL)
{
//printf("\nPoints in cluster!");
tweet_id = atoi(get_name_multipoints(get_point_points_in_cluster(templist_points_in_cluster)));
tweet_index = get_pos_from_id_tweets(tweets, tweets_num, tweet_id);
add_tweet_to_user(users_representatives, u, tweet_index);
//score
templist = tweets[0][tweet_index].coins;
while(templist!=NULL)
{
//user_coin_score(users_representatives, u, tweets, tweet_index, templist);
if(users_representatives[0][u].tot_coins == 0)
{
init_coins_in_user(templist->coin_index, users_representatives, u, coins);
}
else
{
add_coins_in_user(templist->coin_index, users_representatives, u, coins);
}
user_coin_score(users_representatives, u, tweets, tweet_index, templist);
//printf("%d", __LINE__);
templist = templist->next;
}
templist_points_in_cluster = get_next_points_in_cluster(templist_points_in_cluster);
}
struct list_of_tweets* templl = NULL;
templl = users_representatives[0][u].first_tweet;
//printf("\nUser's tweets: ");
// while(templl!=NULL)
// {
// printf("%lld (%lf) ", templl->tweet, tweets[0][templl->tweet].tweet_score);
// templl = templl -> next;
// }
// printf("\n");
// struct coins_in_tweet* templist = NULL;
// templist = tweets[0][tweet_index].coins;
// while(templist!=NULL)
// {
// //user_coin_score(users_representatives, u, tweets, tweet_index, templist);
// if(users_representatives[0][u].tot_coins == 0)
// {
// init_coins_in_user(templist->coin_index, users_representatives, u, coins);
// }
// else
// {
// add_coins_in_user(templist->coin_index, users_representatives, u, coins);
// }
// user_coin_score(users_representatives, u, tweets, tweet_index, templist);
// //printf("%d", __LINE__);
// templist = templist->next;
// }
//u++;
}
return 77;
}
//coins_users
void init_coins_in_user(int coin, struct users* users[], long long pos, struct crypto_coins* coins[])
{
struct coins_in_tweet* newnode = NULL;
newnode = malloc(sizeof(struct coins_in_tweet));
newnode -> coin_index = coin;
// char* tempname = NULL;
// tempname = get_nth_coinref_coin_ref_list(get_coinreflist_crypto_coins(coins,pos),5);
// if(tempname==NULL)
// {
// tempname = get_nth_coinref_coin_ref_list(coins[0][pos].ref_list,1);
// }
// newnode -> coin_name = tempname;
newnode -> next = NULL;
users[0][pos].coins = newnode;
users[0][pos].coins_last_node = users[0][pos].coins;
users[0][pos].tot_coins = 1;
//printf("\nCoin %d inserted to user: %lld", coin, users[0][pos].user_id);
}
void add_coins_in_user(int coin, struct users* users[], long long pos, struct crypto_coins* coins[])
{
struct coins_in_tweet* newnode = NULL, *templist = NULL;
int exists = 0;
templist = users[0][pos].coins;
while (templist!=NULL)
{
if( (templist -> coin_index) == coin )
{
exists = 1;
break;
}
templist = templist -> next;
}
if(!exists)
{
newnode = malloc(sizeof(struct coins_in_tweet));
newnode -> coin_index = coin;
// char* tempname = NULL;
// tempname = get_nth_coinref_coin_ref_list(coins[0][pos].ref_list,5);
// if(tempname==NULL)
// {
// tempname = get_nth_coinref_coin_ref_list(coins[0][pos].ref_list,1);
// }
// newnode -> coin_name = tempname;
newnode -> next = NULL;
(users[0][pos].coins_last_node) -> next = newnode;
users[0][pos].coins_last_node = newnode;
(users[0][pos].tot_coins)++;
//printf("\nCoin %d inserted to user: %lld(tot_coins:%d)", coin, users[0][pos].user_id, users[0][pos].tot_coins);
}
}
int check_if_known_coin(struct users* users[], long long pos, int coin_pos)
{
int known = 0;
struct coins_in_tweet* templist = NULL;
templist = users[0][pos].coins;
while(templist!=NULL)
{
if((templist -> coin_index) == coin_pos)
{
known = 1;
//printf("\nKNOWN - %d", templist -> coin_index);
break;
}
templist = templist -> next;
}
return known;