✌️
This commit is contained in:
		
							parent
							
								
									d8ff37fc45
								
							
						
					
					
						commit
						ed67e3506b
					
				
					 2 changed files with 21 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -5,7 +5,7 @@
 | 
			
		|||
 | 
			
		||||
		<div class="mkw-hashtags--body" :data-mobile="platform == 'mobile'">
 | 
			
		||||
			<p class="fetching" v-if="fetching">%fa:spinner .pulse .fw%%i18n:common.loading%<mk-ellipsis/></p>
 | 
			
		||||
			<p class="empty" v-else-if="stats.length == 0">%fa:exclamation-circle%%i18n:@empty%<mk-ellipsis/></p>
 | 
			
		||||
			<p class="empty" v-else-if="stats.length == 0">%fa:exclamation-circle%%i18n:@empty%</p>
 | 
			
		||||
			<transition-group v-else tag="div" name="chart">
 | 
			
		||||
				<div v-for="stat in stats" :key="stat.tag">
 | 
			
		||||
					<div class="tag">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,8 @@ const rangeB = 1000 * 60 * 120; // 2時間
 | 
			
		|||
const coefficient = 1.5; // 「n倍」の部分
 | 
			
		||||
const requiredUsers = 3; // 最低何人がそのタグを投稿している必要があるか
 | 
			
		||||
 | 
			
		||||
const max = 5;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get trends of hashtags
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -43,7 +45,7 @@ module.exports = () => new Promise(async (res, rej) => {
 | 
			
		|||
		return res([]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	let tags = [];
 | 
			
		||||
	const tags = [];
 | 
			
		||||
 | 
			
		||||
	// カウント
 | 
			
		||||
	data.map(x => x._id).forEach(x => {
 | 
			
		||||
| 
						 | 
				
			
			@ -59,10 +61,10 @@ module.exports = () => new Promise(async (res, rej) => {
 | 
			
		|||
	});
 | 
			
		||||
 | 
			
		||||
	// 最低要求投稿者数を下回るならカットする
 | 
			
		||||
	tags = tags.filter(tag => tag.count >= requiredUsers);
 | 
			
		||||
	const limitedTags = tags.filter(tag => tag.count >= requiredUsers);
 | 
			
		||||
 | 
			
		||||
	//#region 2. 1で取得したそれぞれのタグについて、「直近a分間のユニーク投稿数が今からa分前~今からb分前の間のユニーク投稿数のn倍以上」かどうかを判定する
 | 
			
		||||
	const hotsPromises = tags.map(async tag => {
 | 
			
		||||
	const hotsPromises = limitedTags.map(async tag => {
 | 
			
		||||
		const passedCount = (await Note.distinct('userId', {
 | 
			
		||||
			tags: tag.name,
 | 
			
		||||
			createdAt: {
 | 
			
		||||
| 
						 | 
				
			
			@ -71,7 +73,7 @@ module.exports = () => new Promise(async (res, rej) => {
 | 
			
		|||
			}
 | 
			
		||||
		}) as any).length;
 | 
			
		||||
 | 
			
		||||
		if (tag.count > (passedCount * coefficient)) {
 | 
			
		||||
		if (tag.count >= (passedCount * coefficient)) {
 | 
			
		||||
			return tag;
 | 
			
		||||
		} else {
 | 
			
		||||
			return null;
 | 
			
		||||
| 
						 | 
				
			
			@ -79,13 +81,24 @@ module.exports = () => new Promise(async (res, rej) => {
 | 
			
		|||
	});
 | 
			
		||||
	//#endregion
 | 
			
		||||
 | 
			
		||||
	const hots = (await Promise.all(hotsPromises))
 | 
			
		||||
	// タグを人気順に並べ替え
 | 
			
		||||
	let hots = (await Promise.all(hotsPromises))
 | 
			
		||||
		.filter(x => x != null)
 | 
			
		||||
		.sort((a, b) => b.count - a.count)
 | 
			
		||||
		.map(tag => tag.name)
 | 
			
		||||
		.slice(0, 5);
 | 
			
		||||
		.slice(0, max);
 | 
			
		||||
 | 
			
		||||
	//#region 2で話題と判定されたタグそれぞれについて過去の投稿数グラフを取得する
 | 
			
		||||
	//#region 3. もし上記の方法でのトレンド抽出の結果、求められているタグ数に達しなければ「ただ単に現在投稿数が多いハッシュタグ」に切り替える
 | 
			
		||||
	if (hots.length < max) {
 | 
			
		||||
		hots = hots.concat(tags
 | 
			
		||||
			.filter(tag => hots.indexOf(tag.name) == -1)
 | 
			
		||||
			.sort((a, b) => b.count - a.count)
 | 
			
		||||
			.map(tag => tag.name)
 | 
			
		||||
			.slice(0, max - hots.length));
 | 
			
		||||
	}
 | 
			
		||||
	//#endregion
 | 
			
		||||
 | 
			
		||||
	//#region 2(または3)で話題と判定されたタグそれぞれについて過去の投稿数グラフを取得する
 | 
			
		||||
	const countPromises: Array<Promise<any[]>> = [];
 | 
			
		||||
 | 
			
		||||
	const range = 20;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue