@ashiteam/ashi-smule
Version:
AES encription/decription library for my use
3 lines (2 loc) • 10.6 kB
JavaScript
/*! @ashiteam/ashi-smule 2020-01-29 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const ashi_smule_interfaces_1=require("./models/ashi-smule-interfaces");var PerformanceType;!function(e){e.MyJoin="MYJOIN",e.JoinedMe="JOINEDME",e.Post="POST",e.Group="GROUP",e.Solo="SOLO",e.Unknown="UNKNOWN"}(PerformanceType=exports.PerformanceType||(exports.PerformanceType={}));class AshiSmuleStats{constructor(e){this.userSongData=e,this.myJoins=[],this.othersJoinMe=[],this.updateJoins()}updateJoins(){this.myJoins.splice(0);const e=[],t=[],n=this.userSongData.chanel_songs?this.userSongData.chanel_songs:[],s=this.user;n.forEach(n=>{if(n.ensemble_type&&n.ensemble_type===ashi_smule_interfaces_1.EnsembleType.Duet){const o=this.getOtherSinger(n,!1,s);0!==o.account_id&&e.findIndex(e=>e.account_id===o.account_id)<0&&n.other&&e.push(o),n.child_count&&n.child_count>0&&n.joins.length>0&&n.joins.forEach(e=>{const n=this.getOtherSinger(e,!1,s);if(0!==n.account_id){t.findIndex(e=>!(!e.account_id||e.account_id!==n.account_id))<0&&t.push(n)}})}}),e.forEach(e=>{const t=new AshiCollabData;t.otherUser=e;const o=e.account_id?e.account_id:0;n.forEach(e=>{if(e.ensemble_type&&e.ensemble_type===ashi_smule_interfaces_1.EnsembleType.Duet){const n=this.getOtherSinger(e,!1,s);o===n.account_id&&t.performances.push(e)}}),this.myJoins.push(t)});const o=this.postings;t.forEach(e=>{const t=e.account_id?e.account_id:0,n=new AshiCollabData;n.otherUser=e,o.forEach(e=>{e.joins.forEach(e=>{const o=this.getOtherSinger(e,!0,s);t===o.account_id&&n.performances.push(e)})}),this.othersJoinMe.push(n)}),this.sortJoins(this.myJoins,"count","desc"),this.sortJoins(this.othersJoinMe,"count","desc")}getPerformanceType(e){if(e.ensemble_type){if(e.ensemble_type===ashi_smule_interfaces_1.EnsembleType.Solo)return PerformanceType.Solo;if(e.ensemble_type===ashi_smule_interfaces_1.EnsembleType.Group)return PerformanceType.Group;if(e.ensemble_type===ashi_smule_interfaces_1.EnsembleType.Duet){if(e.child_count&&e.child_count>0)return PerformanceType.Post;{const t=this.user;if(e.owner&&e.owner.account_id===t.account_id)return PerformanceType.JoinedMe;if(e.owner&&e.owner.account_id!==t.account_id)return PerformanceType.MyJoin}}}return PerformanceType.Unknown}getOtherSinger(e,t,n){n||(n=this.user);const s={account_id:0,handle:"Unknown"};return e.other&&e.other.id&&e.other.id!==n.account_id&&(s.account_id=e.other.id,s.handle=e.other.label),0===s.account_id&&e.owner&&e.owner.account_id&&(t||e.owner.account_id!==n.account_id)&&(s.account_id=e.owner.account_id,s.handle=e.owner.handle),s}order(e,t,n=1){const s=e.toLowerCase(),o=t.toLowerCase();return s<o?-1*n:s>o?1*n:0}sortJoins(e,t,n){const s="asc"===n?1:"desc"===n?-1:0;e.sort((e,n)=>{if("name"===t){const t=e.otherUser.handle?e.otherUser.handle:"",o=n.otherUser.handle?n.otherUser.handle:"";return this.order(t,o,s)}return"count"===t?(e.performances.length-n.performances.length)*s:0})}get user(){return this.userSongData&&this.userSongData.user?this.userSongData.user:{}}get chanelSongs(){return this.userSongData&&this.userSongData.chanel_songs?this.userSongData.chanel_songs:[]}get favSongs(){return this.userSongData&&this.userSongData.fav_songs?this.userSongData.fav_songs:[]}get postings(){return this.userSongData&&this.userSongData.chanel_songs?this.userSongData.chanel_songs.filter(e=>e.child_count&&e.child_count>0):[]}get postingsByDate(){const e=new Date(2015,1,1,0,0,0,0);return this.postings.sort((t,n)=>{const s=t.created_at?t.created_at.valueOf():e.valueOf(),o=n.created_at?n.created_at.valueOf():e.valueOf();return s>o?1:s<o?-1:0})}get postingsByTitle(){return this.postings.sort((e,t)=>{const n=e.title?e.title:"",s=t.title?t.title:"";return this.order(n,s)})}get joins(){return this.userSongData&&this.userSongData.chanel_songs?this.userSongData.chanel_songs.filter(e=>e.ensemble_type&&e.ensemble_type===ashi_smule_interfaces_1.EnsembleType.Duet&&(!e.child_count||0===e.child_count)):[]}getPerformancesOfEnsambleType(e){return this.userSongData&&this.userSongData.chanel_songs?this.userSongData.chanel_songs.filter(t=>t.ensemble_type&&t.ensemble_type===e):[]}getPerformancesOfType(e){const t=[];return this.chanelSongs.forEach(n=>{const s=this.getPerformanceType(n);s===e?t.push(n):s!==PerformanceType.Post||e!==PerformanceType.JoinedMe&&e!==PerformanceType.MyJoin||n.joins.forEach(n=>{this.getPerformanceType(n)==e&&t.push(n)})}),t}get solos(){return this.getPerformancesOfEnsambleType(ashi_smule_interfaces_1.EnsembleType.Solo)}get groupSongs(){return this.getPerformancesOfEnsambleType(ashi_smule_interfaces_1.EnsembleType.Group)}get myJoinSongs(){return this.getPerformancesOfType(PerformanceType.MyJoin)}get joinedMeSongs(){return this.getPerformancesOfType(PerformanceType.JoinedMe)}get allDuets(){const e=this.myJoinSongs;return e.push(...this.joinedMeSongs),e}get myJoinCount(){return this.getPerformanceCount(this.myJoins)}get othersJoinMeCount(){return this.getPerformanceCount(this.othersJoinMe)}get myPostingsCount(){return this.userSongData.chanel_songs?this.userSongData.chanel_songs.reduce((e,t)=>t.child_count&&t.child_count>0?e+1:e,0):0}get myTotalPerformances(){return this.userSongData.chanel_songs?this.userSongData.chanel_songs.length:0}getPerformanceCount(e){return e.reduce((e,t)=>e+t.performances.length,0)}getEnsambleTypeCount(e){return this.userSongData.chanel_songs?this.userSongData.chanel_songs.reduce((t,n)=>n.ensemble_type&&n.ensemble_type===e?t+1:t,0):0}get mySoloCount(){return this.getEnsambleTypeCount(ashi_smule_interfaces_1.EnsembleType.Solo)}get myGroupSongCount(){return this.getEnsambleTypeCount(ashi_smule_interfaces_1.EnsembleType.Group)}get biggestJoin(){return this.postings.reduce((e,t)=>e.joins.length>t.joins.length?e:t)}get smallestJoin(){return this.postings.reduce((e,t)=>e.joins.length<t.joins.length?e:t)}get uniqueSongTitleArray(){const e=[];return this.chanelSongs.forEach(t=>{const n=(t.title?t.title.toLowerCase():"").trim();e.findIndex(e=>e.toLowerCase().trim()===n)<0&&t.title&&e.push(t.title.trim())}),e}get uniqueSingersArray(){const e=this.user;let t=[];return this.allDuets.forEach(n=>{const s=this.getOtherSinger(n,!0,e);t.findIndex(e=>e.account_id===s.account_id)<0&&s&&t.push(s)}),t.sort((e,t)=>{const n=e.handle?e.handle:"",s=t.handle?t.handle:"";return this.order(n,s)})}getPerfString(e,t,n){t||(t=this.chanelSongs),n||(n=this.user);const s=e.toLowerCase().trim(),o=t.filter(e=>e.title&&e.title.toLowerCase().trim()===s);let r=`${e} : ${o.length}\r\n`;return o.forEach(e=>{const t=this.getPerformanceType(e);if(t===PerformanceType.Solo)r+=" SOLO\r\n";else if(t===PerformanceType.Group)r+=` GROUP (${e.other_performers?e.other_performers.length:0})\r\n`,e.other_performers&&e.other_performers.forEach(e=>{r+=` ${e.handle}\r\n`});else if(t===PerformanceType.Post)r+=` POST - Joins (${e.joins.length})\r\n`,e.joins.forEach(e=>{const t=this.getOtherSinger(e,!0,n).handle;r+=` ${t}\r\n`});else{const t=this.getOtherSinger(e,!1,n).handle;r+=` ${t}\r\n`}}),r}getString(){let e="";const t=this.user,n=(this.favSongs,this.chanelSongs);e+="\r\n",e+="User Info\r\n",e+=` Handle: ${t.handle}\r\n`,e+=` Name: ${t.first_name} ${t.last_name}\r\n`,e+=` Location: ${t.location}\r\n`,e+="\r\n",e+="Following Info\r\n",e+=` Following: ${t.followees}\r\n`,e+=` Followers: ${t.followers}\r\n`;const s=this.getNumber(t.followees),o=this.getNumber(t.followers);e+=s>0?` Ratio: 1 - ${o/s}\r\n`:" Ratio: 1 - infinity\r\n";const r=this.myPostingsCount,i=this.myJoinCount,a=this.othersJoinMeCount,h=this.mySoloCount,c=this.myGroupSongCount,l=this.biggestJoin,u=this.smallestJoin;e+="\r\n",e+="Songs Info\r\n",e+=` ${t.handle} sang ${i} songs with ${this.myJoins.length} people\r\n`,e+=` ${this.othersJoinMe.length} people joind ${t.handle} and created ${a} collaborations\r\n`,e+=` Total Postings = ${r} : ${this.postings.length}\r\n`,e+=` Average Joins Per Post = ${a/r}\r\n`,e+=` Joins\r\n Min = ${u.joins.length} - (${u.title}),\r\n Max = ${l.joins.length} - (${l.title})\r\n`,e+=` Total Solo = ${h} : ${this.solos.length}\r\n`,e+=` Total Group Songs = ${c} : ${this.groupSongs.length}\r\n`,e+=` Total Joins = ${i} : ${this.myJoinSongs.length}\r\n`,e+=` Total Joins With ${t.handle} = ${this.joinedMeSongs.length}\r\n`,e+=` Total Recordings = ${r+i+c+h}\r\n`,this.myTotalPerformances!=r+i+c+h&&(e+=` Problem Total Recordings Alt = ${this.myTotalPerformances}\r\n`);e+="\r\n",e+=`${t.handle} Joining Others - Song Count ${i} - People Count ${this.myJoins.length}\r\n`,e+=` ${"Name".padEnd(20," ")} Users\r\n`,e+=` ${"----".padEnd(20," ")} -----\r\n`,this.myJoins.forEach(t=>{const n=t.otherUser&&t.otherUser.handle?t.otherUser.handle:"Unknown";e+=` ${n.padEnd(20)}`,e+=` ${t.performances.length}\r\n`}),e+="\r\n",e+=`Others Joining ${t.handle} - Song Count ${a} : ${this.joinedMeSongs.length} - People Count ${this.othersJoinMe.length}\r\n`,e+=` ${"Name".padEnd(20," ")} Users\r\n`,e+=` ${"----".padEnd(20," ")} -----\r\n`,this.othersJoinMe.forEach(t=>{const n=t.otherUser&&t.otherUser.handle?t.otherUser.handle:"Unknown";e+=` ${n.padEnd(20)}`,e+=` ${t.performances.length}\r\n`});const g=this.uniqueSongTitleArray.sort((e,t)=>this.order(e,t));e+="\r\n",e+=`Total Unique Tracks = ${g.length}\r\n`,g.forEach(s=>{e+="\r\n",e+=this.getPerfString(s,n,t)}),e+="\r\n";const d=this.solos;e+=`Solos by ${t.handle} (${d.length} Songs)\r\n`,d.forEach(t=>{e+=` ${t.title}\r\n`}),e+="\r\n";const m=this.postings;e+=`Songs posted by ${t.handle} (${m.length} Songs)\r\n`,m.forEach(t=>{const n=t.title?t.title:"";e+=` ${n.padEnd(50)} (${t.joins.length} Joins)\r\n`});const p=this.uniqueSingersArray;e+="\r\n",e+=`${t.handle} has duets with ${p.length} singers\r\n`;const f=`${t.handle} Joined`.padStart(27);return e+=` ${"Name".padEnd(20)} ${f} ${"Other Joined".padStart(14)} ${"Total".padStart(10)} ${"Ratio".padStart(12)}\r\n`,p.forEach(t=>{const n=t.handle?t.handle:"",s=this.myJoins.filter(e=>e.otherUser.account_id===t.account_id),o=s.length>0?s[0].performances.length:0,r=`${o}`.padStart(27),i=this.othersJoinMe.filter(e=>e.otherUser.account_id===t.account_id),a=i.length>0?i[0].performances.length:0,h=`${a}`.padStart(14),c=`${o+a}`.padStart(10),l=(a/o).toFixed(2).padStart(12);e+=` ${n.padEnd(20)} ${r} ${h} ${c} ${l}\r\n`}),e}getNumber(e){if(e){if(e.length>0&&"k"==e[e.length-1].toLowerCase()){return 1e3*Number.parseFloat(e.substr(0,e.length-1))}return Number.parseInt(e)}return 0}}exports.AshiSmuleStats=AshiSmuleStats;class AshiCollabData{constructor(){this.otherUser={},this.performances=[]}}exports.AshiCollabData=AshiCollabData;