<commit_before>Rx = require 'rx'
glob = require 'glob'
pathMod = require 'path'
fs = require 'fs'
_ = require "lodash"
vdf = require 'vdf'

validStateFlags =
  1: no
  4: yes
  32: no

readACF = (target) ->
  readFile = Rx.Observable.fromNodeCallback fs.readFile
  readFile(target, 'utf8').map vdf.parse

getPathACFs = (pathDetails, i) ->
  globBetter = Rx.Observable.fromNodeCallback glob
  steamappsPath = pathMod.join(pathDetails.path, "steamapps")
  globBetter("appmanifest_*.acf", cwd: steamappsPath)
    .map (matches) ->
      paths = _.map matches, (x) ->
        pathMod.join(steamappsPath, x)
      {path: pathDetails, i: i, apps: paths}

readAllACFs = (pathObj) ->
  Rx.Observable.fromArray(pathObj.apps)
    .flatMap (path) ->
      readACF(path).map (obj) -> {acfPath: path, data: obj}
    .map ({acfPath, data: {AppState}}) ->
      {path: pathObj.path, i: pathObj.i, gameInfo: AppState, acfPath: acfPath}
    .filter ({gameInfo}) ->
      state = parseInt(gameInfo.StateFlags)
      _.all _.pairs(validStateFlags), ([flag, val]) ->
        ((state & flag) is flag) is val

buildGameObject = ({path, i, gameInfo, acfPath}) ->
  fullPath = pathMod.join(
    path.path,
    "steamapps",<commit_msg>Filter for installed games properly<commit_after>Rx = require 'rx'
glob = require 'glob'
pathMod = require 'path'
fs = require 'fs'
_ = require "lodash"
vdf = require 'vdf'

validStateFlags =
  1: no
  4: yes
  32: no

readACF = (target) ->
  readFile = Rx.Observable.fromNodeCallback fs.readFile
  readFile(target, 'utf8').map vdf.parse

getPathACFs = (pathDetails, i) ->
  globBetter = Rx.Observable.fromNodeCallback glob
  steamappsPath = pathMod.join(pathDetails.path, "steamapps")
  globBetter("appmanifest_*.acf", cwd: steamappsPath)
    .map (matches) ->
      paths = _.map matches, (x) ->
        pathMod.join(steamappsPath, x)
      {path: pathDetails, i: i, apps: paths}

readAllACFs = (pathObj) ->
  Rx.Observable.fromArray(pathObj.apps)
    .flatMap (path) ->
      readACF(path).map (obj) -> {acfPath: path, data: obj}
    .map ({acfPath, data: {AppState}}) ->
      {path: pathObj.path, i: pathObj.i, gameInfo: AppState, acfPath: acfPath}
    .filter ({gameInfo}) ->
      state = parseInt(gameInfo.StateFlags)
      _.all _.pairs(validStateFlags), ([flag, val]) ->
        ((state & parseInt(flag)) is parseInt(flag)) is val

buildGameObject = ({path, i, gameInfo, acfPath}) ->
  fullPath = pathMod.join(
    path.path,
    "steamapps",
{'fraction_non_alphanumeric': 0.1510966693744923, 'fraction_numerical': 0.004061738424045491, 'mean_word_length': 3.4863387978142075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '4294529', 'n_tokens_mistral': 901, 'n_tokens_neox': 884, 'n_words': 211}