Exemple #1
0
 def testSetKV(self):
     x = globalconfig()
     x.setKV('a', 1)
     x.setKV('b', 3)
     y = globalconfig()
     y.setKV('dd', 4)
     result = {'a': 1, 'b': 3, 'dd': 4}
     self.assertEqual(y.getKVs(), result)
Exemple #2
0
import wavefront_api_client as wave_api
import datetime as dt 
import logging
from metadata.globalconfig import globalconfig 
import urllib.parse
 
# logging
logging.basicConfig(format='%(asctime)s %(message)s')
logger = logging.getLogger('apis')


globalConfig =  globalconfig()

#set up python Wavefront client
client  = None

def dequote(url):
    durl = urllib.parse.unquote(url)
    durl = durl.replace('+',' ')
    return durl


def createWavefrontClient():
    config = wave_api.Configuration()    
    config.host = globalConfig.getValueByKey('WAVEFRONT_ENDPOINT')
    token = globalConfig.getValueByKey('WAVEFRONT_TOKEN')
    if (config.host=='' or token==''):
        logger.error("wavefront endpoint or token is null")
        return None
    try:
        global client 
def TwoDataSetSameDistribution(dataset1, dataset2, alpha=DEFAULT_PAIRWISE_THRESHOLD, algorithm=ANY, bound= IS_UPPER_BOUND):
  config = globalconfig()
  
  size = min(len(dataset1),len(dataset2))
  p = 0
  if algorithm == WILCOXON:
      try:
          stat, p = wilcoxon(dataset1, dataset2,"pratt", True)
          if p >= alpha:
              return True, p, WILCOXON,size>=config.getValueByKey("MIN_WILCOXON_DATA_POINTS")
          else:
              return False, p, WILCOXON, size>=config.getValueByKey("MIN_WILCOXON_DATA_POINTS")
      except Exception as e:
          try:
              if (bound== IS_UPPER_BOUND):
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'greater')
              elif bound == IS_LOWER_BOUND :
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'less')
              else:
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'two-sided')
              if p >= alpha:
                  return True, p , MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")
              else:
                  return False, p,  MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS") 
          except Exception as e:
                  return True, 0, ERROR , size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS") 
  elif algorithm == KRUSKAL:
      try:
          stat, p = kruskal(dataset1, dataset2)
          if p >= alpha:
              return True, p,KRUSKAL, size>=config.getValueByKey("MIN_KRUSKAL_DATA_POINTS")
          else:
              return False, p,KRUSKAL, size>=config.getValueByKey("MIN_KRUSKAL_DATA_POINTS")
      except Exception as e:
          try:
              if (bound== IS_UPPER_BOUND):
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'greater')
              elif bound == IS_LOWER_BOUND :
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'less')
              else:
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'two-sided')
              if p >= alpha:
                  return True, p , MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")
              else:
                  return False, p,  MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")
          except Exception as e:
                  return True, 0, ERROR, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS") 
  elif algorithm == ALL:
      try:
          if (bound== IS_UPPER_BOUND):
            stat, p = mannwhitneyu(dataset1, dataset2,True, 'greater')
          elif bound == IS_LOWER_BOUND :
            stat, p = mannwhitneyu(dataset1, dataset2,True, 'less')
          else:
            stat, p = mannwhitneyu(dataset1, dataset2,True, 'two-sided')
          if p >= alpha:
              stat, p = wilcoxon(dataset1, dataset2,"pratt", True)
              if p >= alpha:
                  stat, p = kruskal(dataset1, dataset2)
                  if p >= alpha:
                      return True, p, ALL, size>=config.getValueByKey("MIN_KRUSKAL_DATA_POINTS")
                  else:
                      return False, p, KRUSKAL, size>=config.getValueByKey("MIN_KRUSKAL_DATA_POINTS")
              else:
                  return False, p, WILCOXON, size>=config.getValueByKey("MIN_WILCOXON_DATA_POINTS")
          else:
              return False, p, MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")

      except Exception as e:
          try:
              if (bound== IS_UPPER_BOUND):
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'greater')
              elif bound == IS_LOWER_BOUND :
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'less')
              else:
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'two-sided')
              if p >= alpha:
                  return True, p , MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")  
              else:
                  return False, p,  MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS") 
          except Exception as e:
                  return True, 0, ERROR ,  MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS") 
  elif algorithm == ANY:
      try:
          if (bound== IS_UPPER_BOUND):
              stat, p = mannwhitneyu(dataset1, dataset2,True, 'greater')
          elif bound == IS_LOWER_BOUND :
              stat, p = mannwhitneyu(dataset1, dataset2,True, 'less')
          else:
              stat, p = mannwhitneyu(dataset1, dataset2,True, 'two-sided')
          if p >= alpha:
              return True, p, MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")
          stat, p = wilcoxon(dataset1, dataset2,"pratt", True)
          if p >= alpha:
              return True, p, WILCOXON, size>=config.getValueByKey("MIN_WILCOXON_DATA_POINTS")
          stat, p = kruskal(dataset1, dataset2)
          if p >= alpha:
                return True, p, KRUSKAL, size>=config.getValueByKey("MIN_KRUSKAL_DATA_POINTS")
          return False, p, ANY, size>=config.getValueByKey("MIN_KRUSKAL_DATA_POINTS")
      except Exception as e:
          try:
              if (bound== IS_UPPER_BOUND):
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'greater')
              elif bound == IS_LOWER_BOUND :
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'less')
              else:
                  stat, p = mannwhitneyu(dataset1, dataset2,True, 'two-sided')
              if p >= alpha:
                  return True, p , MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS") 
              else:
                  return False, p,  MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS") 
          except Exception as e:
                  return True, 0, ERROR , size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")  
  else:
      try:
          if (bound== IS_UPPER_BOUND):
              stat, p = mannwhitneyu(dataset1, dataset2,True, 'greater')
          elif bound == IS_LOWER_BOUND :
              stat, p = mannwhitneyu(dataset1, dataset2,True, 'less')
          else:
              stat, p = mannwhitneyu(dataset1, dataset2,True, 'two-sided')
          if p >= alpha:
              return True, p , MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")  
          else:
              return False, p,  MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS") 
      except Exception as e:
          if str(e) ==  "All numbers are identical in mannwhitneyu" :
              return True, 0, MANN_WHITE, size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")                 
  return True,  0, ERROR,  size>=config.getValueByKey("MIN_MANN_WHITE_DATA_POINTS")