Skip to content

Latest commit

 

History

History
212 lines (173 loc) · 5.58 KB

Zad2.md

File metadata and controls

212 lines (173 loc) · 5.58 KB

Szymon Rękawek


Maszyna:

Windows 8.1 x64
Intel Core i3-2350M 
8 GB RAM

Mongo:

$ mongo --version
MongoDB shell version: 2.8.0-rc0

Uruchomione z opcją

--storageEngine wiredtiger

Zadanie 2:

Import pliku getglue_smaple:

mongoimport -d mydb -c getglue < getglue_sample.json

Czas trwania:

28m

alt tag

alt tag

alt tag

Zapytania:

Klasa z rozwiązaniem w javie

Reżyserzy mający imię na literę 'H', którzy mają na koncie najwięcej filmów

JS

db.getglue.aggregate( 
 	{ $match: {"director": { $regex: '^H.*'}} },
	{ $match: {"modelName": "movies"} },
    { $group: 
    	{
    		_id: {"Typ programu":"$modelName", "Reżyser": "$director"}, 
    		count: {$sum: 1}
    	}
    },
    { $sort: {count: -1} },
    { $limit : 5 } );

JAVA

public static void directorsWithMostMovies(DBCollection coll) {
	DBObject Xmatch = (DBObject) JSON.parse("{ $match: {'director': { $regex: '^H.*'}} }");
	DBObject Xmatch2 = (DBObject) JSON.parse("{ $match: {'modelName': 'movies'} }");
	DBObject Xgroup = (DBObject) JSON.parse("{ $group: {_id: {'Typ programu':'$modelName', 'Reżyser': '$director'}, count: {$sum: 1}}");
	DBObject Xsort = (DBObject) JSON.parse(" { $sort: {count: -1} }");
	DBObject Xlimit = (DBObject) JSON.parse("{ $limit : 10}");
		
	AggregationOutput output = coll.aggregate(Xmatch, Xmatch2, Xgroup, Xsort, Xlimit);
	System.out.println(output.results());
}
Reżyser Typ programu Ilość wystąpień
Henry Selick movies 70
Hayo Miyazaki movies 44
Harold Ramis movies 12
Herbert Ross movies 7
Hamilton Luske movies 5

Najczęściej występujące filmy na literkę 'M'.

JS

db.getglue.aggregate(
    { $match: {"title": { $regex: '^M.*'}} },
    { $group: 
        {_id: {Tytuł : "$title"}, 
        count: {$sum: 1}} 
    },
    { $sort: {count: -1} },
    { $limit : 5 } );

JAVA

public static void mostCommonMovieNames(DBCollection coll) {
	DBObject Xmatch = (DBObject) JSON.parse("{ $match: {'title': { $regex: '^M.*'}} }");
	DBObject Xgroup = (DBObject) JSON.parse("{ $group: {_id: {'Tytuł' : '$title'}, count: {$sum: 1}} }");
	DBObject Xsort = (DBObject) JSON.parse("{ $sort: {count: -1} }");
	DBObject Xlimit = (DBObject) JSON.parse("{ $limit : 10}");
		
	AggregationOutput output = coll.aggregate(Xmatch, Xgroup, Xsort, Xlimit);
	System.out.println(output.results());
} 
Tytuł Wystąpienia
Modern Family 74294
Marvel's The Avengers 64356
Mad Men 42611
MythBusters 29089
Monsters, Inc 19805

Filmy, które mają najwięcej komentarzy.

JS

db.getglue.aggregate( 
	{ $match: 
		{ action: "Comment" }
	},
	{ $group: 
		{ _id: { Tytuł : "$title" }, count: {"$sum": 1} } 
	}, 
	{ $sort: 
		{ "count": -1 } 
	}, 
	{ $limit: 5 } );

Java

public static void mostCommentedMovies(DBCollection coll) {
	DBObject Xmatch = (DBObject) JSON.parse("{ $match: { action: 'Comment' }}");
	DBObject Xgroup = (DBObject) JSON.parse("{ $group: { _id: { Tytuł : '$title' }, 'count': {'$sum': 1} } }");
	DBObject Xsort = (DBObject) JSON.parse("{ $sort: { 'count': -1 } }");
	DBObject Xlimit = (DBObject) JSON.parse("{ $limit: 10 }");
		
	AggregationOutput output = coll.aggregate(Xmatch, Xgroup, Xsort, Xlimit);
	System.out.println(output.results());
	}
Tytuł Komentarze
Slumdog Millionaire 30
True Blood 15
Harry Potter and the Deathly Hallows: Part II 13
Avatar 11
The Dark Knight 11

Najczęściej lajkujący użytkownicy.

JS

db.sgetglue.aggregate( 
	{ $match: 
		{ action: "Liked" }
	},
	{ $group: 
		{ _id: { Użytkownik : "$userId" }, count: {"$sum": 1} } 
	}, 
	{ $sort: 
		{ "count": -1 } 
	}, 
	{ $limit: 5 } );

JAVA

public static void mostLikingUsers(DBCollection coll) {
	DBObject Xmatch = (DBObject) JSON.parse("{ $match:{ action: 'Liked' }}");
	DBObject Xgroup = (DBObject) JSON.parse("{ $group: { _id: { Użytkownik : '$userId' }, 'count': {'$sum': 1} } }");
	DBObject Xsort = (DBObject) JSON.parse("{ $sort: { 'count': -1 } }");
	DBObject Xlimit = (DBObject) JSON.parse("{ $limit: 10 }");
		
	AggregationOutput output = coll.aggregate(Xmatch, Xgroup, Xsort, Xlimit);
	System.out.println(output.results());
}
Użytkownik Lajki
jesusvarelaacosta 13562
gluemanblues 12932
s3v3ns 11520
johnnym2001 11436
bangwid 9237

Porównanie czasów:

alt tag

Javascript Java
1 8:50 15:29
2 11:53 12:22
3 11:16 12:01
4 9:25 12:34