Skip to content

Commit

Permalink
Finally finished (fr this time)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin-droid authored May 6, 2024
1 parent 53bf019 commit 36f88c3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
43 changes: 27 additions & 16 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ async function main() {
if (precheck) {
await topics.topicLabeller(5);
}
const stats = await topics.statsAnalyser();
const tags = Object.entries(stats.topics.tags).map(([key, value]) => ({
key: key,
value: value
}));
const stats = await topics.statsAnalyser(extraordinarytitles);
const tags = Object.entries(stats.topics.tags)
.map(([key, value]) => ({
key: key,
value: value
}))
.sort((a, b) => b.value.plays - a.value.plays); // Sorting tags by number of plays in descending order

const artistss = stats.artists;

// Create a map to store most popular artist by plays for each topic
Expand Down Expand Up @@ -122,35 +125,43 @@ async function main() {
});
topicsTableHTML += "</table>";

let artistTableHTML = "<h2>✨Artists</h2><table>";
let artistTableHTML = "<h2>✨Artists</h2><table><tr><td><h3>Artist</h3></td><td><h3>Tag</h3></td><td><h3>Entries</h3></td><td><h3>Time</h3></td><td><h3>Plays</h3></td></tr>";
let artistInfo = {};

artistss.sort((a, b) => {
// Sum total plays for artist b
const bTotalPlays = Object.values(b.tags.tags).reduce((total, tag) => total + tag.plays, 0);
// Sum total plays for artist a
const aTotalPlays = Object.values(a.tags.tags).reduce((total, tag) => total + tag.plays, 0);
return bTotalPlays - aTotalPlays; // Sorting in descending order
});

artistss.forEach((artist) => {
// Ensure that artist.tags and artist.tags.tags exist and are objects
if (artist.tags && typeof artist.tags.tags === "object") {
let totalPlays = 0;
let totalTime = 0;
let artistTags = Object.entries(artist.tags.tags).sort(
(a, b) => b[1].plays - a[1].plays
); // Sorting each artist's tags by plays in descending order

// Iterate over each tag
Object.entries(artist.tags.tags).forEach(([key, tag]) => {
artistTags.forEach(([key, tag]) => {
if (!artistInfo[artist.name]) {
artistInfo[artist.name] = {
tags: [],
entries: [],
time: [],
plays: []
plays: [],
totalPlays: 0,
totalTime: 0
};
}
artistInfo[artist.name].tags.push(key);
artistInfo[artist.name].entries.push(tag.entries);
artistInfo[artist.name].time.push(tag.time);
artistInfo[artist.name].plays.push(tag.plays);
totalPlays += tag.plays;
totalTime += tag.time;
artistInfo[artist.name].totalPlays += tag.plays;
artistInfo[artist.name].totalTime += tag.time;
});

artistInfo[artist.name].totalPlays = totalPlays;
artistInfo[artist.name].totalTime = totalTime;
}
});

Expand All @@ -172,7 +183,7 @@ async function main() {
0
)}</td><td>${rh.getFormattedTime(info.totalTime)}</td><td>${
info.totalPlays
}</td></tr>`;
}</td></tr><hr/>`;
}
});

Expand Down
2 changes: 1 addition & 1 deletion right-hand.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ module.exports = {
{
role: "system",
content:
'Given is a list of authors with duplicate names in the database. To be more effective, you are given the task of merging them together. Note that this response is hooked to live upstream API so the response format must be strictly maintained in JSON.\nOutput format (do not output anything apart from this and do not output this in a code bracket or include comments). Strictly output JSON only. If a generic name exists then delete it. Do not delete any author if it has more than 3 entries. When merging, the first name as well as the last name must strictly be the same (order and language does not matter). This does not mean you should delete any author with less than 3 entries. For merge, the rule is to merge similar names with lower entries (targets) with larger entries (source). This is done to save upstream API requests. If duplicates or stupid names do not exist, omit the entry outright.\n```\n{\n "edits-required": true,\n "merge": [{\n "Source": <sourceID>, //If duplicate exists (integer)\n "Targets": [<Array of target IDs>] //If duplicate exists (integer array)\n },\n ... //Other merges\n],\n"delete": [ <original ID>, // IDs to delete\n... //Other deletes\n]\n}\n```\n\nIf no deletes exist then return an empty array for the value and if no merges exist then too return an empty array for the value. Do not break the schema. If both do not exist then return the following.\n\n```\n{\n "edits-required": false\n}\n```'
'Given is a list of authors with duplicate names in the database. To be more effective, you are given the task of merging them together. Note that this response is hooked to live upstream API so the response format must be strictly maintained in JSON.\nOutput format (do not output anything apart from this and do not output this in a code bracket or include comments). Strictly output JSON only. If a generic name exists then delete it. Do not delete any author if it has more than 3 entries. When merging, the first name as well as the last name must strictly be the same (order (this means fname and lname are interchangeable) and language (this means you can merge English names into Marathi names or so on with any language) does not matter) Merge condition: trimIntermediaries(anyLanguage(fname)+anyLanguage(lname))=trimIntermediaries(anyLanguage(fname)+anyLanguage(lname)) or trimIntermediaries(anyLanguage(fname)+anyLanguage(lname))=trimIntermediaries(anyLanguage(lname)+anyLanguage(fname)). This does not mean you should delete any author with less than 3 entries. For merge, the rule is to merge similar names with lower entries (targets) with larger entries (source). This is done to save upstream API requests. If duplicates or stupid names do not exist, omit the entry outright.\n```\n{\n "edits-required": true,\n "merge": [{\n "Source": <sourceID>, //If duplicate exists (integer)\n "Targets": [<Array of target IDs>] //If duplicate exists (integer array)\n },\n ... //Other merges\n],\n"delete": [ <original ID>, // IDs to delete\n... //Other deletes\n]\n}\n```\n\nIf no deletes exist then return an empty array for the value and if no merges exist then too return an empty array for the value. Do not break the schema. If both do not exist then return the following.\n\n```\n{\n "edits-required": false\n}\n```'
},
{
role: "user",
Expand Down
6 changes: 3 additions & 3 deletions topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ module.exports.checkTags = async (customData) => {
};


module.exports.statsAnalyser = async (customData) => {
const bzdata = customData || (await rh.buzzsprout.read());
module.exports.statsAnalyser = async (extraOrdinaryTitlesAI) => {
const bzdata = (await rh.buzzsprout.read());

// Extract unique artists from the data, skipping empty artist fields
const uniqueArtists = new Set(); // Create a new Set to store unique artist names
bzdata.forEach((item) => {
if (item.artist) {
if (item.artist && !extraOrdinaryTitlesAI.some((title) => title.id == item.id)) {
// Check if the artist field is not empty
uniqueArtists.add(item.artist);
}
Expand Down

0 comments on commit 36f88c3

Please sign in to comment.