Message Boards Message Boards

2
|
2629 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Dataset for monitoring Art Contest votes

Posted 2 years ago

There are probably better ways to show the votes of Art Contest 2022, but here is one way:

Clear[ArtContest2022Votes];
ArtContest2022Votes[url_String : "https://community.wolfram.com/groups/-/m/t/2498984"] :=     
  Block[{replyPattern, votesPattern, userPattern, userImagePattern, 
    xmlObj, siteURL, aUserVotes, dsUserVotes, dsUserVotes2},

   replyPattern = XMLElement["div", {"class" -> "reply_posts", "id" -> _, ___}, ___]; 
   votesPattern = XMLElement[ "div", {"class" -> "like-counter like-counter-margin", "id" -> _}, {v_}] :> v;
   userPattern = XMLElement["img", {"class" -> "avatar", "alt" -> name_, "src" -> portraitURL_, "width" -> _}, {}] :> {name, portraitURL};
   userImagePattern = XMLElement["div", {"class" -> "user-image"}, ___];

   xmlObj = Import[url, "XMLObject"];
   siteURL = "https://community.wolfram.com/";
   aUserVotes = Map[Cases[#, userPattern, \[Infinity]][[1]] -> Cases[#, votesPattern, \[Infinity]][[1]] &, Cases[xmlObj, replyPattern, \[Infinity]]];

   dsUserVotes = Dataset@Map[{#[[1, 1]], Import[siteURL <> #[[1, 2]]], #[[2]]} &, aUserVotes];
   dsUserVotes2 = dsUserVotes[All, AssociationThread[{"Name", "Avatar", "Votes"}, #] &];
   dsUserVotes2 = dsUserVotes2[All, Append[#, <|"Votes" -> ToExpression[#Votes]|>] &];
   dsUserVotes2[ReverseSortBy[{#Votes, #Name} &]]
  ];
dsACVotes = ArtContest2022Votes[];
Dimensions[dsACVotes]

(*{45, 3}*)
SeedRandom[39];
RandomSample[dsACVotes, 4]
SeedRandom[32];
Multicolumn@Normal[RandomSample[dsACVotes, 6]] /. x_?AssociationQ :> Dataset[x]
POSTED BY: Anton Antonov
2 Replies

Nice code, Anton! Votes are great to show support to artists. But perhaps votes are not the best indicator of what people really like more or less in such type of competitions, -- as votes depend on chronology. The earlier submissions on average get more votes, a simple bias. The longer something is public, the more is the statistical pool of people who sees it, and the more is their fraction who vote. Just a thought, still - a great example of web-scraping!

POSTED BY: Vitaliy Kaurov

Good point, and properly articulated -- I was thinking about that too...

I think a "temporal normalization" indicator can be added to the result set.

(Also, votes are not necessarily used by the evaluation committee.)


[...] still - a great example of web-scraping!

Thanks! I thought this is a good "eat your own dog food" example.

POSTED BY: Anton Antonov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract