Last active
August 29, 2015 14:17
-
-
Save bobend/ac3048f08b3dd79ccd4d to your computer and use it in GitHub Desktop.
volume for 2014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bytesToSize(bytes) { | |
if (bytes == 0) return '0 Byte'; | |
var k = 1000; | |
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; | |
var i = Math.floor(Math.log(bytes) / Math.log(k)); | |
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i]; | |
} | |
function getDuration(timeMillis) { | |
var units = [{ | |
label: "millis", | |
mod: 1000, | |
}, { | |
label: "seconds", | |
mod: 60, | |
}, { | |
label: "minutes", | |
mod: 60, | |
}, { | |
label: "hours", | |
mod: 24, | |
}, { | |
label: "days", | |
mod: 7, | |
}, { | |
label: "weeks", | |
mod: 52, | |
}]; | |
var duration = new Object(); | |
var x = timeMillis; | |
for (i = 0; i < units.length; i++) { | |
var tmp = x % units[i].mod; | |
duration[units[i].label] = tmp; | |
x = (x - tmp) / units[i].mod; | |
} | |
var str = ""; | |
if (duration.weeks > 0) | |
str += duration.weeks + " weeks "; | |
if (duration.days > 0) | |
str += duration.days + " days "; | |
if (duration.hours > 0) | |
str += duration.hours + " hours "; | |
if (duration.minutes > 0) | |
str += duration.minutes + " mins "; | |
if (duration.seconds > 0) | |
str += duration.seconds + " secs "; | |
if (duration.millis > 0) | |
str += duration.millis + " millis"; | |
return str; | |
} | |
var startDate = new Date(); | |
var manifestCount = 0; | |
db.tempvolume.save({ | |
_id: "AudioResource", | |
millis: 0.0, | |
bytesSpace: 0.0, | |
count: 0 | |
}) | |
db.tempvolume.save({ | |
_id: "VideoResource", | |
millis: 0.0, | |
bytesSpace: 0.0, | |
count: 0 | |
}) | |
db.programcard.find({ | |
"PrimaryAssetKind": { | |
$exists: true | |
}, | |
"Assets.0": { | |
$exists: true | |
} | |
}).batchSize(50).forEach( | |
function(programcard) { | |
if (programcard != null) { | |
var bytesSpace = 0; | |
var millis = 0; | |
var assetRef = db.assetreference.findOne({ | |
_id: programcard.PrimaryAssetUri.split('~/bar/')[1] | |
}); | |
if (assetRef.Uri.lastIndexOf('~/manifest/', 0) === 0) { | |
var manifest = db.manifest.findOne({ | |
_id: assetRef.Uri.split('~/manifest/')[1] | |
}); | |
if (manifest.EndPublish > ISODate("2014-01-01T00:00:00Z") && manifest.StartPublish > ISODate("2015-01-01T00:00:00Z")) { | |
manifestCount++; | |
var index; | |
if (manifest.Qualities != null) { | |
millis += manifest.Duration; | |
for (index = 0; index < manifest.Qualities.length; ++index) { | |
bytesSpace += manifest.Qualities[index].Size; | |
} | |
} | |
} | |
} | |
db.tempvolume.update({ | |
_id: programcard.PrimaryAssetKind | |
}, { | |
$inc: { | |
millis: millis, | |
bytesSpace: bytesSpace, | |
count: 1 | |
} | |
}) | |
} else print('programcard undefined'); | |
} | |
); | |
db.tempvolume.find({}).forEach( | |
function(tempv) { | |
print (tempv._id); | |
printjson (getDuration(tempv.millis)); | |
printjson (bytesToSize(tempv.bytesSpace)); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment