<commit_before>import { SearchResult } from '../types';
import {
  acceptBaseUrl,
  baseTaskUrlWorker,
  baseRequeserUrlWorker,
  turkopticonBaseUrl
} from '../constants';

const contactBaseUrl = 'https://www.mturk.com/mturk/contact?requesterId=';
const requesterSearchBaseUrl =
  'https://www.mturk.com/mturk/searchbar?requesterId=';

const removExtraneousWhiteSpace = (el: string): string => {
  return el.replace(/\s\s+/g, ' ');
};

export const generateMarkdownExport = (hit: SearchResult): string => {
  const {
    title,
    groupId,
    requester,
    reward,
    timeAllotted,
    batchSize,
    description,
    qualsRequired
  } = hit;

  const quals = qualsRequired.length === 0 ? 'None' :
  qualsRequired.map(removExtraneousWhiteSpace).join('; ');

  if (requester.turkopticon) {
    const {
      reviews,
      tos_flags,
      attrs: { comm, fair, fast, pay }
    } = requester.turkopticon;

    // tslint:disable:max-line-length
    return `> **Title:** [${title}](${acceptBaseUrl}${groupId})  
    **Worker:** [Preview](${baseTaskUrlWorker}${groupId}/tasks) | [Accept](${baseTaskUrlWorker}${groupId}/tasks/accept_random) | [Requester](${baseRequeserUrlWorker}${requester.id}/projects)  
    **Requester:** [Xtractions](${requesterSearchBaseUrl}${requester.id}) [${requester.id}] ([Contact](${contactBaseUrl}${requester.id}))  
    **[TO](${turkopticonBaseUrl}${requester.id}):** [Pay: ${pay}] [Fast: ${fast}] [Comm: ${comm}] [Fair: ${fair}] [Reviews: ${reviews}] [ToS: ${tos_flags}]  
    **Reward:** $${reward} 
    **Duration:** ${timeAllotted}  
    **Available:** ${batchSize}  
    **Description:** ${description}
    **Requirements:** ${quals}`;
    
  } else {
    return `> **Title:** [${title}](${acceptBaseUrl}${groupId})  
    **Worker:** [Preview](${baseTaskUrlWorker}${groupId}/tasks) | [Accept](${baseTaskUrlWorker}${groupId}/tasks/accept_random) | [Requester](${baseRequeserUrlWorker}${requester.id}/projects)  
    **Requester:** [Xtractions](${requesterSearchBaseUrl}${requester.id}) [${requester.id}] ([Contact](${contactBaseUrl}${requester.id}))  
    **[TO](No data)]  
    **Reward:** $${reward} 
    **Duration:** ${timeAllotted}  
    **Available:** ${batchSize}  
    **Description:** ${description}
    **Requirements:** ${quals}`;
  }
};<commit_msg>Fix contact link in Markdown export.<commit_after>import { SearchResult } from '../types';
import {
  acceptBaseUrl,
  baseTaskUrlWorker,
  baseRequeserUrlWorker,
  turkopticonBaseUrl
} from '../constants';

const contactBaseUrl = 'https://www.mturk.com/mturk/contact?requesterId=';
const requesterSearchBaseUrl =
  'https://www.mturk.com/mturk/searchbar?requesterId=';

const removExtraneousWhiteSpace = (el: string): string => {
  return el.replace(/\s\s+/g, ' ');
};

export const generateMarkdownExport = (hit: SearchResult): string => {
  const {
    title,
    groupId,
    requester,
    reward,
    timeAllotted,
    batchSize,
    description,
    qualsRequired
  } = hit;

  const quals =
    qualsRequired.length === 0
      ? 'None'
      : qualsRequired.map(removExtraneousWhiteSpace).join('; ');

  if (requester.turkopticon) {
    const {
      reviews,
      tos_flags,
      attrs: { comm, fair, fast, pay }
    } = requester.turkopticon;

    // tslint:disable:max-line-length
    return `> **Title:** [${title}](${acceptBaseUrl}${groupId})  
    **Worker:** [Preview](${baseTaskUrlWorker}${groupId}/tasks) | [Accept](${baseTaskUrlWorker}${groupId}/tasks/accept_random) | [Requester](${baseRequeserUrlWorker}${requester.id}/projects)  
    **Requester:** [${requester.name}](${requesterSearchBaseUrl}${requester.id}) ([Contact](${contactBaseUrl}${requester.id}))  
    **[TO](${turkopticonBaseUrl}${requester.id}):** [Pay: ${pay}] [Fast: ${fast}] [Comm: ${comm}] [Fair: ${fair}] [Reviews: ${reviews}] [ToS: ${tos_flags}]  
    **Reward:** $${reward} 
    **Duration:** ${timeAllotted}  
    **Available:** ${batchSize}  
    **Description:** ${description}
    **Requirements:** ${quals}`;
  } else {
    return `> **Title:** [${title}](${acceptBaseUrl}${groupId})  
    **Worker:** [Preview](${baseTaskUrlWorker}${groupId}/tasks) | [Accept](${baseTaskUrlWorker}${groupId}/tasks/accept_random) | [Requester](${baseRequeserUrlWorker}${requester.id}/projects)  
    **Requester:** [${requester.name}](${requesterSearchBaseUrl}${requester.id}) [${requester.id}] ([Contact](${contactBaseUrl}${requester.id}))  
    **[TO](No data)]  
    **Reward:** $${reward} 
    **Duration:** ${timeAllotted}  
    **Available:** ${batchSize}  
    **Description:** ${description}
    **Requirements:** ${quals}`;
  }
};
{'fraction_non_alphanumeric': 0.20654529692241005, 'fraction_numerical': 0.00043346337234503684, 'mean_word_length': 4.641809290953545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '71231', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1567, 'n_words': 236}