<commit_before>/**
 * 
 */
package net.thenumenorean.essence.pl;

import java.util.ArrayList;
import java.util.List;

import org.bson.Document;

import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Sorts;

import net.thenumenorean.essence.MongoDriver;

/**
 * @author <NAME>
 *
 */
public class InsertOrderPlaylist extends PlaylistGenerator {

	/**
	 * 
	 */
	public InsertOrderPlaylist() {
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.thenumenorean.essence.pl.PlaylistGenerator#regeneratePlaylist(net.
	 * thenumenorean.essence.MongoDriver)
	 */
	@Override
	public void regeneratePlaylist(MongoDriver md) {

		// clear the existing playlist to populate it
		md.getPlaylistColection().deleteMany(Filters.ne("rank", -1));

		List<Document> docs = new ArrayList<Document>();

		int rank = 0;
		for (Document d : md.getRequestColection().find().sort(Sorts.ascending("timestamp"))) {
			docs.add(new Document("rank", rank++)
					.append("track_id", d.getObjectId("song_id"))
					.append("req_id", d.getObjectId("_id"))
					.append("user", d.getString("user"))
					.append("timestamp", d.getInteger("timestamp")));
		}
		
		md.getPlaylistColection().insertMany(docs);
	}

}<commit_msg>Fixed error when there are no requests<commit_after>/**
 * 
 */
package net.thenumenorean.essence.pl;

import java.util.ArrayList;
import java.util.List;

import org.bson.Document;

import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Sorts;

import net.thenumenorean.essence.MongoDriver;

/**
 * @author <NAME>
 *
 */
public class InsertOrderPlaylist extends PlaylistGenerator {

	/**
	 * 
	 */
	public InsertOrderPlaylist() {
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.thenumenorean.essence.pl.PlaylistGenerator#regeneratePlaylist(net.
	 * thenumenorean.essence.MongoDriver)
	 */
	@Override
	public void regeneratePlaylist(MongoDriver md) {

		// clear the existing playlist to populate it
		md.getPlaylistColection().deleteMany(Filters.ne("rank", -1));

		List<Document> docs = new ArrayList<Document>();

		int rank = 0;
		for (Document d : md.getRequestColection().find().sort(Sorts.ascending("timestamp"))) {
			docs.add(new Document("rank", rank++)
					.append("track_id", d.getObjectId("song_id"))
					.append("req_id", d.getObjectId("_id"))
					.append("user", d.getString("user"))
					.append("timestamp", d.getInteger("timestamp")));
		}
		
		if(!docs.isEmpty())
			md.getPlaylistColection().insertMany(docs);
	}

}
{'fraction_non_alphanumeric': 0.1563236449332286, 'fraction_numerical': 0.0015710919088766694, 'mean_word_length': 4.15587044534413, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1118490', 'n_tokens_mistral': 955, 'n_tokens_neox': 843, 'n_words': 145}