<commit_before>import contextlib
import datetime
import io
import math
import os
import zipfile
import shutil
import sys
import tempfile
import time
from math import cos

import networkx
import numpy
import pandas as pd
import shapefile as shp

"""
Various unrelated utility functions.
"""

# Below is a race condition, so do it only on import.
# Is there a portable way to do this?
current_umask = os.umask(0)
os.umask(current_umask)

TORADIANS = 3.141592653589793 / 180.
EARTH_RADIUS = 6378137.


def set_process_timezone(TZ):
    """
    Parameters
    ----------
    TZ: string
    """
    try:
        prev_timezone = os.environ['TZ']
    except KeyError:
        prev_timezone = None
    os.environ['TZ'] = TZ
    time.tzset()  # Cause C-library functions to notice the update.
    return prev_timezone


def wgs84_distance(lat1, lon1, lat2, lon2):
    """Distance (in meters) between two points in WGS84 coord system."""
    dLat = math.radians(lat2 - lat1)
    dLon = math.radians(lon2 - lon1)
    a = (math.sin(dLat / 2) * math.sin(dLat / 2) +
         math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) *
         math.sin(dLon / 2) * math.sin(dLon / 2))
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    d = EARTH_RADIUS * c
    return d

<commit_msg>Reset time conversion rules also on Windows<commit_after>import contextlib
import ctypes
import datetime
import io
import math
import os
import zipfile
import shutil
import sys
import tempfile
import time
from math import cos

import networkx
import numpy
import pandas as pd
import shapefile as shp

"""
Various unrelated utility functions.
"""

# Below is a race condition, so do it only on import.
# Is there a portable way to do this?
current_umask = os.umask(0)
os.umask(current_umask)

TORADIANS = 3.141592653589793 / 180.
EARTH_RADIUS = 6378137.


def set_process_timezone(TZ):
    """
    Parameters
    ----------
    TZ: string
    """
    try:
        prev_timezone = os.environ['TZ']
    except KeyError:
        prev_timezone = None
    os.environ['TZ'] = TZ
    try:
        time.tzset()  # Cause C-library functions to notice the update.
    except AttributeError:    # tzset() does not work on Windows
        system_time = SystemTime()
        lpSystemTime = ctypes.pointer(system_time)
        ctypes.windll.kernel32.GetLocalTime(lpSystemTime)

    return prev_timezone


class SystemTime(ctypes.Structure):
    _fields_ = [
        ('wYear', ctypes.c_int16),
        ('wMonth', ctypes.c_int16),
        ('wDayOfWeek', ctypes.c_int16),
        ('wDay', ctypes.c_int16),
        ('wHour', ctypes.c_int16),
        ('wMinute', ctypes.c_int16),
        ('wSecond', ctypes.c_int16),
        ('wMilliseconds', ctypes.c_int16)]


def wgs84_distance(lat1, lon1, lat2, lon2):
    """Distance (in meters) between two points in WGS84 coord system."""
    dLat = math.radians(lat2 - lat1)
    dLon = math.radians(lon2 - lon1)
    a = (math.sin(dLat / 2) * math.sin(dLat / 2) +
         math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) *
         math.sin(dLon / 2) * math.sin(dLon / 2))
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    d = EARTH_RADIUS * c
    return d


{'fraction_non_alphanumeric': 0.11607423718150361, 'fraction_numerical': 0.03586033343818811, 'mean_word_length': 2.8970588235294117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4960034', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1103, 'n_words': 307}