model_stats.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* a simple plugin that outputs some general information about a model... the point here is to demo how to use _mmmk from a plugin */
  2. {
  3. 'interfaces' : [{'method':'GET', 'url=':'/stats'}],
  4. 'localcontext' : {},
  5. 'types2instances' :
  6. function()
  7. {
  8. var model = _utils.jsonp(_mmmk.read()),
  9. t2i = {};
  10. console.warn(model, typeof(model))
  11. for( var id in model.nodes )
  12. {
  13. var node = model.nodes[id];
  14. t2i[node['$type']] = t2i[node['$type']] || 0;
  15. t2i[node['$type']]++;
  16. }
  17. return _utils.jsons(t2i,null,'\t');
  18. },
  19. 'csworker' :
  20. function(resp,method,uri,reqData,wcontext)
  21. {
  22. var self = this;
  23. _do.chain(
  24. [__wHttpReq(method, uri+'?wid='+wcontext.__aswid, reqData)])(
  25. function()
  26. {
  27. __postMessage(
  28. {'statusCode':200,
  29. 'changelog':
  30. [{'op':'SYSOUT',
  31. 'text':'CS MODEL STATS\n'+self.types2instances()}],
  32. 'sequence#':__sequenceNumber(),
  33. 'respIndex':resp});
  34. },
  35. function(err) {__postInternalErrorMsg(resp,err);}
  36. );
  37. },
  38. 'asworker' :
  39. function(resp,method,uri,reqData,wcontext)
  40. {
  41. __postMessage(
  42. {'statusCode':200,
  43. 'changelog':
  44. [{'op':'SYSOUT',
  45. 'text':'AS MODEL STATS\n'+this.types2instances()}],
  46. 'sequence#':__sequenceNumber(),
  47. 'respIndex':resp});
  48. }
  49. }