Skip to content
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.

Commit

Permalink
finish statistics scipion
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto committed Feb 10, 2017
1 parent 8b729b9 commit ef40040
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ env['CC'] = os.environ.get('CC')
env['CXX'] = os.environ.get('CXX')
env['LINKERFORPROGRAMS'] = os.environ.get('LINKERFORPROGRAMS')
env['CCFLAGS'] = os.environ.get('CCFLAGS', '').split()
cxxFlags = os.environ.get('CXXFLAGS', '')
cxxFlags = os.environ.get('CXXFLAGS', '')
if os.environ.get('DEBUG', '0') == 'True': #FIXME, use 1, true, yes...
cxxFlags += ' -g'
else:
Expand Down
38 changes: 38 additions & 0 deletions pyworkflow/apps/pw_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,40 @@ def main():
sys.stderr.write('Error: %s\n' % sys.exc_info()[1])
sys.exit(1)

def chekReport(Config):
"Check if protocol statistics should be collected"
reportOn = Config.get('VARIABLES','SCIPION_NOTIFY')
print("ooooo", reportOn)
if reportOn=='False':
print("aaaaa")
# This works for Python 2.x. and Python 3
try:
input = raw_input
except NameError:
pass
print("""The Scipion developers team would appreciate if you
anonymously share your protocol usage statistics. These statistics
just include the name of the protocols executed in your machine.
We understand, of course, that some people do not wish to have any
information collected from them. You can enable or disable the
collection of information at any time (by default it is disabled).
This information will help our team to understand the popularity of
the different protocols and prioritize support for the more popular ones.
Please, note that the statistics are completely anonymous and do not include
protocol parameters, file names or any data that can be used to identify
your account, machine or data. In the URL
https://github.com/I2PC/scipion/wiki/Collecting-Usage-Statistics-for-Scipion
you may see examples of the transmited data as well as the
statistics created with it. You can always deactivate/activate
this option by editing the file $HOME/.config/scipion/scipion.conf
and setting the variable SCIPION_NOTIFY to False/True respectively.
""")

prompt = input("Press [y|Y]<enter> is you want to share data, otherwise just press <enter>: ")
if prompt == 'y' or prompt=='Y':
Config.set('VARIABLES','SCIPION_NOTIFY','True')

def createConf(fpath, ftemplate, remove=[], keep=[]):
"Create config file in fpath following the template in ftemplate"
Expand Down Expand Up @@ -143,12 +177,16 @@ def createConf(fpath, ftemplate, remove=[], keep=[]):
for section in set(cf.sections()) - set(keep):
cf.remove_section(section)


# Update with our guesses.
if 'BUILD' in cf.sections():
for options in [guessJava(), guessMPI()]:
for key in options:
if key in cf.options('BUILD'):
cf.set('BUILD', key, options[key])
# Collecting Protocol Usage Statistics
elif 'VARIABLES' in cf.sections():
chekReport(cf)

# Create the actual configuration file.
cf.write(open(fpath, 'w'))
Expand Down
2 changes: 1 addition & 1 deletion pyworkflow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
Expand Down
3 changes: 2 additions & 1 deletion pyworkflow/gui/project/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ProjectNotifier(object):
""" Implement different types of notifications about a given
project. Currently, the protocols in a workflow will be sent.
"""

def __init__(self, project):
self.project = project

Expand Down Expand Up @@ -122,7 +123,7 @@ def notifyWorkflow(self):
dataDict = {'project_uuid': self._getUuid(),
'project_workflow': projectWorfklow}

urlName = os.environ.get('SCIPION_NOTIFY_URL', '').strip()
urlName = os.environ.get('SCIPION_NOTIFY_URL', 'http://calm-shelf-73264.herokuapp.com/report_protocols/api/workflow/workflow/').strip()
urlName += "addOrUpdateWorkflow/"
t = threading.Thread(target=lambda: self._sendData(urlName, dataDict))
t.start() # will execute function in a separate thread
Expand Down
9 changes: 3 additions & 6 deletions pyworkflow/tests/em/protocols/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ def setUpClass(cls):
setupTestProject(cls)

def _getUrl(self):
if not pwutils.envVarOn('SCIPION_NOTIFY'):
return ''

return os.environ.get('SCIPION_NOTIFY_URL', '').strip()
return os.environ.get('SCIPION_NOTIFY_URL', 'http://calm-shelf-73264.herokuapp.com/report_protocols/api/workflow/workflow/').strip()

def test_projectNotifier(self):
""" Execute a protocol and then report on it
Expand All @@ -50,6 +47,7 @@ def test_projectNotifier(self):

#change periodicy in notification
os.environ["SCIPION_NOTIFY_SECONDS"] = "30"
os.environ["SCIPION_NOTIFY"] = "True"
if not url:
print "SCIPION_NOTIFY and SCIPION_NOTIFY_URL should be defined!"
print "A test server is at Heroku, you can setup as:"
Expand All @@ -59,7 +57,6 @@ def test_projectNotifier(self):

url = url.replace("workflow/workflow/",
"workflow/protocol/?name=ProtStress")

results = json.loads(urllib2.urlopen(url).read())
objects = results["objects"]
if (len(objects)!=0):
Expand All @@ -77,7 +74,7 @@ def test_projectNotifier(self):
#create and execute protocol stress
prot1 = self.newProtocol(ProtStress, **kwargs)
prot1.setObjLabel('stress')
self.proj.launchProtocol(prot1, wait=True)
self.proj.launchProtocol(prot1, wait=True)


#we want to test this class: ProjectNotifier
Expand Down

0 comments on commit ef40040

Please sign in to comment.