@@ -105,6 +105,26 @@ def log_node_added(self, widget_name, extended_widget=None):
105105 def set_node_type (self , addition_type ):
106106 self .__node_addition_type = addition_type
107107
108+ def send_statistics (self ):
109+ if release and config .settings ()["error-reporting/send-statistics" ]:
110+ if os .path .isfile (statistics_path ):
111+ with open (statistics_path ) as f :
112+ data = json .load (f )
113+ try :
114+ r = requests .post (server_url , files = {'file' : json .dumps (data )})
115+ if r .status_code != 200 :
116+ log .warning ("Error communicating with server while attempting to send "
117+ "usage statistics." )
118+ return
119+ # success - wipe statistics file
120+ log .info ("Usage statistics sent." )
121+ with open (statistics_path , 'w' ) as f :
122+ json .dump ([], f )
123+ except (ConnectionError , requests .exceptions .RequestException ):
124+ log .warning ("Connection error while attempting to send usage statistics." )
125+ except Exception :
126+ log .warning ("Failed to send usage statistics." )
127+
108128 def write_statistics (self ):
109129 if not release :
110130 log .info ("Not sending usage statistics (non-release version of Orange detected)." )
@@ -134,24 +154,9 @@ def write_statistics(self):
134154
135155 data .append (statistics )
136156
137- def store_data (d ):
138- with open (statistics_path , 'w' ) as f :
139- json .dump (d , f )
140-
141- try :
142- r = requests .post (server_url , files = {'file' : json .dumps (data )})
143- if r .status_code != 200 :
144- log .warning ("Error communicating with server while attempting to send "
145- "usage statistics." )
146- store_data (data )
147- return
148- # success - wipe statistics file
149- log .info ("Usage statistics sent." )
150- with open (statistics_path , 'w' ) as f :
151- json .dump ([], f )
152- except (ConnectionError , requests .exceptions .RequestException ):
153- log .warning ("Connection error while attempting to send usage statistics." )
154- store_data (data )
157+ with open (statistics_path , 'w' ) as f :
158+ json .dump (data , f )
159+
155160
156161 @staticmethod
157162 def set_last_search_query (query ):
0 commit comments